<template>
  <view class="text-survival-container">
      <!-- 每日一言横幅（可关闭） -->
      <view v-if="showDailyQuote && todayQuote" class="daily-quote-banner" @click="showDailyQuote = false">
        <text class="quote-text">{{ todayQuote.text }}</text>
        <text class="quote-meta">第{{ day }}天 · {{ todayQuote.theme === 'survival' ? '生存' : todayQuote.theme === 'motivation' ? '励志' : todayQuote.theme === 'wisdom' ? '智慧' : '幽默' }}</text>
        <text class="quote-close">×</text>
      </view>
      
      <view class="header">
        <text class="title">🏝️ 荒岛求生</text>
        <view class="header-actions">
          <button class="restart-btn" @click="resetGame">重开</button>
          <button class="save-btn" @click="openSaveModal">存档</button>
        <view class="badges">
          <text class="badge new">NEW</text>
          <text class="badge survival">生存</text>
          </view>
        </view>
      </view>

      <!-- 简化状态栏（点击查看详情） -->
      <view class="status-mini-bar" @click="showStatusSheet = true">
        <text class="status-item" :class="{ 'critical': hp < 30 }">❤️{{ hp }}%</text>
        <text class="status-item" :class="{ 'critical': hunger < 20 }">🍎{{ hunger }}%</text>
        <text class="status-item" :class="{ 'critical': energy < 20 }">⚡{{ energy }}%</text>
        <text class="status-item" :class="{ 'critical': thirst < 20 }">💧{{ thirst }}%</text>
        <text class="status-item" :class="{ 'critical': sanity < 20 }">🧠{{ sanity }}%</text>
        <text class="more-hint">详情 ▼</text>
      </view>

      <view class="ai-bar">
        <label class="ai-switch">
          <switch :checked="aiEnabled" @change="toggleAI"/>
          <text class="ai-label">AI事件（测试版，可能不稳定）</text>
        </label>
        <button class="ai-test-btn" :disabled="!aiEnabled || aiBusy" @click="generateAIEvent">{{ aiBusy ? '生成中...' : '测试AI' }}</button>
      </view>
      <!-- 当前位置信息 -->
      <view class="current-location-info" v-if="currentLocation">
        <view class="location-card">
          <text class="location-icon">{{ currentLocation.icon }}</text>
          <view class="location-details">
            <text class="location-name">当前位置：{{ currentLocation.name }}</text>
            <text class="location-desc">{{ currentLocation.description }}</text>
          </view>
        </view>
      </view>
      <view class="scene" :class="{ 'scene-animate': sceneAnimating }">
        <view class="scene-content">
          <text class="scene-text" :class="{ 'typing': isTyping }">{{ displayText }}</text>
          <view v-if="isTyping" class="typing-indicator">...</view>
        </view>
        <view class="scene-effects">
          <view v-if="showEffect" class="effect-overlay" :class="effectType"></view>
        </view>
      </view>

      <view class="options">
        <button class="option-btn" v-for="(opt, idx) in options" :key="idx" @click="choose(opt)" :class="{ 'option-disabled': isActionDisabled }">
          <text class="option-text">{{ opt.label }}</text>
          <view v-if="opt.risk" class="risk-indicator" :class="'risk-' + opt.risk">{{ opt.risk }}</view>
        </button>
        <button class="option-btn special" @click="openCrafting" :class="{ 'option-disabled': isActionDisabled }">
          <text class="option-text">🔨 制作 / 背包</text>
          <view class="special-indicator">制作</view>
        </button>
      </view>

      <view class="log-section">
        <text class="log-title">事件记录</text>
        <scroll-view class="log-list" scroll-y>
          <view v-for="(line, i) in logs" :key="i" class="log-line">{{ line }}</view>
        </scroll-view>
      </view>

      <!-- 底部Tab导航 -->
      <view class="bottom-tabs">
        <view class="tab-item" :class="{ 'active': currentTab === 'survival' }" @click="switchTab('survival')">
          <text class="tab-icon">🏝️</text>
          <text class="tab-text">生存</text>
        </view>
        <view class="tab-item" :class="{ 'active': currentTab === 'map' }" @click="switchTab('map')">
          <text class="tab-icon">🗺️</text>
          <text class="tab-text">地图</text>
        </view>
        <view class="tab-item" :class="{ 'active': currentTab === 'build' }" @click="switchTab('build')">
          <text class="tab-icon">🏗️</text>
          <text class="tab-text">建筑</text>
        </view>
        <view class="tab-item" :class="{ 'active': currentTab === 'tech' }" @click="switchTab('tech')">
          <text class="tab-icon">🔬</text>
          <text class="tab-text">科技</text>
        </view>
        <view class="tab-item" :class="{ 'active': currentTab === 'inventory' }" @click="switchTab('inventory')">
          <text class="tab-icon">🎒</text>
          <text class="tab-text">背包</text>
        </view>
      </view>

    <!-- 地图探索弹窗 -->
    <MapModal 
      :visible="showMapModal" 
      :mapTiles="mapTiles" 
      :currentLocationId="currentLocationId"
      :energy="energy"
      @explore="exploreTile"
      @close="closeMapModal"
    />

    <!-- 建筑管理弹窗 -->
    <BuildingModal 
      :visible="showBuildModal" 
      :buildings="buildings" 
      :inventory="inventory"
      @build="buildBuilding"
      @close="closeBuildModal"
    />

    <!-- 科技研究弹窗 -->
    <TechModal 
      :visible="showTechModal" 
      :techs="techs" 
      :researchPoints="researchPoints"
      @research="startResearch"
      @close="closeTechModal"
    />

    <!-- 存档管理弹窗 -->
    <SaveModal 
      :visible="showSaveModal" 
      :saveSlots="saveSlots"
      :autoSaveData="autoSaveData"
      @save="saveGame"
      @load="loadSave"
      @delete="deleteSave"
      @loadAutoSave="loadAutoSave"
      @saveAutoSave="saveAutoSave"
      @deleteAutoSave="deleteAutoSave"
      @close="closeSaveModal"
    />

    <ChoiceModal :visible="showChoice" :event="currentEvent" :inventory="inventory" :buffs="buffs" @select="onSelectOption" @close="showChoice=false"/>
    <CraftingSheet :visible="showCraft" :inventory="inventory" :recipes="recipes" @craft="craftItem" @close="showCraft=false"/>
    
    <!-- 状态详情Sheet -->
    <SheetModal :visible="showStatusSheet" title="详细状态" @close="showStatusSheet = false">
      <view class="status-detail-sheet">
        <!-- 主要属性 -->
        <view class="status-section">
          <text class="section-title">🎮 角色状态</text>
          
          <view class="detail-item">
            <view class="item-header">
              <text class="item-label">❤️ 生命值</text>
              <text class="item-value" :style="{ color: getStatusLevel(hp).color }">{{ hp }}% · {{ getStatusLevel(hp).text }}</text>
            </view>
            <view class="progress-bar">
              <view class="progress-fill hp" :style="{ width: hp + '%' }"></view>
            </view>
          </view>
          
          <view class="detail-item">
            <view class="item-header">
              <text class="item-label">🍎 饥饿度</text>
              <text class="item-value" :style="{ color: getStatusLevel(hunger).color }">{{ hunger }}% · {{ getStatusLevel(hunger).text }}</text>
            </view>
            <view class="progress-bar">
              <view class="progress-fill hunger" :style="{ width: hunger + '%' }"></view>
            </view>
          </view>
          
          <view class="detail-item">
            <view class="item-header">
              <text class="item-label">⚡ 精力值</text>
              <text class="item-value" :style="{ color: getStatusLevel(energy).color }">{{ energy }}% · {{ getStatusLevel(energy).text }}</text>
            </view>
            <view class="progress-bar">
              <view class="progress-fill energy" :style="{ width: energy + '%' }"></view>
            </view>
          </view>
          
          <view class="detail-item">
            <view class="item-header">
              <text class="item-label">💧 口渴度</text>
              <text class="item-value" :style="{ color: getStatusLevel(thirst).color }">{{ thirst }}% · {{ getStatusLevel(thirst).text }}</text>
            </view>
            <view class="progress-bar">
              <view class="progress-fill thirst" :style="{ width: thirst + '%' }"></view>
            </view>
          </view>
          
          <view class="detail-item">
            <view class="item-header">
              <text class="item-label">🧠 理智值</text>
              <text class="item-value" :style="{ color: getStatusLevel(sanity).color }">{{ sanity }}% · {{ getStatusLevel(sanity).text }}</text>
            </view>
            <view class="progress-bar">
              <view class="progress-fill sanity" :style="{ width: sanity + '%' }"></view>
            </view>
          </view>
        </view>
        
        <!-- Buff/Debuff -->
        <view class="status-section" v-if="buffs && buffs.length > 0">
          <text class="section-title">✨ 当前效果</text>
          <view class="buff-list">
            <view class="buff-item" v-for="(buff, index) in buffs" :key="index">
              <text class="buff-icon">{{ buff.type === 'positive' ? '✨' : '⚠️' }}</text>
              <view class="buff-info">
                <text class="buff-name">{{ buff.name }}</text>
                <text class="buff-desc">{{ buff.description }}</text>
              </view>
            </view>
          </view>
        </view>
        
        <!-- 技能树 -->
        <view class="status-section">
          <text class="section-title">🎯 技能树</text>
          <view class="skills-list">
            <view class="skill-item" v-for="(skill, key) in getGameSkills()" :key="key">
              <view class="skill-header">
                <text class="skill-icon">{{ skill.icon }}</text>
                <view class="skill-info">
                  <text class="skill-name">{{ skill.name }} Lv.{{ skill.level }}</text>
                  <view class="skill-exp-bar">
                    <view class="skill-exp-fill" :style="{ width: (skill.exp / skill.nextLevelExp * 100) + '%' }"></view>
                  </view>
                  <text class="skill-exp-text">{{ skill.exp }} / {{ skill.nextLevelExp }} 经验</text>
                </view>
              </view>
              <text class="skill-bonus">{{ skill.bonus }}</text>
            </view>
          </view>
        </view>
        
        <!-- 已解锁结局 -->
        <view class="status-section">
          <text class="section-title">🏆 已解锁结局 ({{ getAchievedEndings().length }}/7)</text>
          <view class="endings-list">
            <view class="ending-item" v-for="(endingId, index) in getAchievedEndings()" :key="index">
              <text class="ending-icon">{{ getEndingIcon(endingId) }}</text>
              <text class="ending-name">{{ getEndingTitle(endingId) }}</text>
            </view>
            <view class="ending-item locked" v-if="getAchievedEndings().length < 7">
              <text class="ending-icon">🔒</text>
              <text class="ending-name">还有 {{ 7 - getAchievedEndings().length }} 个结局待解锁</text>
            </view>
          </view>
        </view>
        
        <!-- 生存统计 -->
        <view class="status-section">
          <text class="section-title">📊 生存统计</text>
          <view class="stats-grid">
            <view class="stat-card">
              <text class="stat-icon">📅</text>
              <text class="stat-label">生存天数</text>
              <text class="stat-value">第 {{ day }} 天</text>
            </view>
            <view class="stat-card">
              <text class="stat-icon">🗺️</text>
              <text class="stat-label">当前位置</text>
              <text class="stat-value">{{ currentLocation ? currentLocation.name : '未知' }}</text>
            </view>
            <view class="stat-card">
              <text class="stat-icon">🏗️</text>
              <text class="stat-label">已建建筑</text>
              <text class="stat-value">{{ buildings.length }} 个</text>
            </view>
            <view class="stat-card">
              <text class="stat-icon">🔬</text>
              <text class="stat-label">已解锁科技</text>
              <text class="stat-value">{{ techs.filter(t => t.unlocked).length }} 项</text>
            </view>
          </view>
        </view>
      </view>
    </SheetModal>
  </view>
</template>

<script>
import ChoiceModal from './components/ChoiceModal.vue'
import CraftingSheet from './components/CraftingSheet.vue'
import BuildingModal from './components/BuildingModal.vue'
import TechModal from './components/TechModal.vue'
import MapModal from './components/MapModal.vue'
import SaveModal from './components/SaveModal.vue'
import SheetModal from '@/components/SheetModal.vue'
import aiService from '@/utils/ai-service.js'

// 引入新的游戏管理器（纯前端）
import gameManager from '@/utils/game/game-manager.js'
import dailyQuote from '@/utils/ai/daily-quote.js'
import npcMood from '@/utils/ai/npc-mood.js'

// 引入游戏配置数据
import { buildings } from './config/buildings.js'
import { techs } from './config/techs.js'

export default {
  components: { 
    ChoiceModal, 
    CraftingSheet, 
    BuildingModal, 
    TechModal, 
    MapModal, 
    SaveModal,
    SheetModal
  },
  data() {
    return {
      hp: 100,
      hunger: 60,
      energy: 80,
      day: 1,
      // 新增属性（来自game-manager）
      thirst: 100,
      sanity: 100,
      temperature: 37,
      // 状态详情Sheet
      showStatusSheet: false,
      // 每日一言
      showDailyQuote: true,
      todayQuote: null,
      logs: [],
      sceneText: '你清晨醒来，潮湿的风从密林吹来。你需要寻找食物与安全的落脚点。',
      displayText: '',
      isTyping: false,
      typeTimer: null,
      sceneAnimating: false,
      showEffect: false,
      effectType: '',
      isActionDisabled: false,
      options: [],
      // 事件系统
      showChoice: false,
      currentEventId: 'intro_beach',
      currentEvent: null,
      events: {},
      // 制作与背包
      showCraft: false,
      inventory: { 
        wood: 0, stone: 0, vine: 0, water: 0, 
        metal: 0, mud: 0, crystals: 0, 
        herbs: 0, mushrooms: 0, sand: 0, 
        reeds: 0, cactus: 0, shells: 0
      },
      recipes: [
        // 基础工具
        { 
          id: 'torch', 
          name: '火把', 
          type: '工具', 
          requires: { wood: 1, vine: 1 }, 
          effectDesc: '夜间探索更安全（叙事加成）',
          prerequisites: [],
          category: '基础工具'
        },
        { 
          id: 'bandage', 
          name: '绷带', 
          type: '消耗品', 
          requires: { vine: 1 }, 
          effectDesc: '回复少量生命',
          prerequisites: [],
          category: '医疗用品'
        },
        { 
          id: 'trap', 
          name: '简易陷阱', 
          type: '工具', 
          requires: { wood: 2, vine: 1 }, 
          effectDesc: '提升觅食收益（叙事加成）',
          prerequisites: [],
          category: '狩猎工具'
        },
        { 
          id: 'rope', 
          name: '绳索', 
          type: '材料', 
          requires: { vine: 3 }, 
          effectDesc: '制作其他物品的材料',
          prerequisites: [],
          category: '基础材料'
        },
        { 
          id: 'hammer', 
          name: '石锤', 
          type: '工具', 
          requires: { stone: 2, wood: 1 }, 
          effectDesc: '建筑效率 +50%',
          prerequisites: ['basic_tools'],
          category: '建筑工具'
        },
        // 中级工具
        { 
          id: 'metal_knife', 
          name: '金属刀', 
          type: '工具', 
          requires: { metal: 2, wood: 1 }, 
          effectDesc: '采集效率 +100%',
          prerequisites: ['metalworking'],
          category: '金属工具'
        },
        { 
          id: 'water_filter', 
          name: '净水器', 
          type: '工具', 
          requires: { stone: 3, sand: 2, vine: 2 }, 
          effectDesc: '净化水源，淡水产量 +2/天',
          prerequisites: ['water_purification'],
          category: '生活工具'
        },
        { 
          id: 'medicine_kit', 
          name: '医疗包', 
          type: '消耗品', 
          requires: { herbs: 3, vine: 2, water: 1 }, 
          effectDesc: '回复大量生命',
          prerequisites: ['medicine'],
          category: '医疗用品'
        },
        { 
          id: 'fishing_net', 
          name: '渔网', 
          type: '工具', 
          requires: { vine: 5, wood: 2 }, 
          effectDesc: '捕鱼效率 +200%',
          prerequisites: ['basic_tools'],
          category: '狩猎工具'
        },
        { 
          id: 'storage_box', 
          name: '储物箱', 
          type: '建筑', 
          requires: { wood: 8, metal: 2 }, 
          effectDesc: '增加存储容量 +100',
          prerequisites: ['advanced_building'],
          category: '建筑'
        },
        // 高级工具
        { 
          id: 'advanced_trap', 
          name: '高级陷阱', 
          type: '工具', 
          requires: { metal: 3, wood: 4, vine: 2 }, 
          effectDesc: '狩猎效率 +300%',
          prerequisites: ['metalworking', 'engineering'],
          category: '狩猎工具'
        },
        { 
          id: 'solar_panel', 
          name: '太阳能板', 
          type: '建筑', 
          requires: { metal: 10, crystals: 5, glass: 3 }, 
          effectDesc: '能源产量 +5/天',
          prerequisites: ['energy_systems'],
          category: '能源建筑'
        },
        { 
          id: 'defense_wall', 
          name: '防御墙', 
          type: '建筑', 
          requires: { stone: 20, metal: 5, wood: 10 }, 
          effectDesc: '防御力 +150%',
          prerequisites: ['defense_systems'],
          category: '防御建筑'
        },
        { 
          id: 'advanced_medicine', 
          name: '高级药品', 
          type: '消耗品', 
          requires: { herbs: 5, crystals: 2, water: 3 }, 
          effectDesc: '回复大量生命和精力',
          prerequisites: ['advanced_medicine'],
          category: '医疗用品'
        }
      ],
      // 自动事件触发系统
      autoEventCooldown: 0,
      lastAutoEventDay: 0,
      autoEventProbability: 0.3,
      // 事件触发条件
      eventTriggers: {
        lowHealth: { threshold: 30, probability: 0.6, type: 'medical' },
        lowHunger: { threshold: 20, probability: 0.5, type: 'survival' },
        lowEnergy: { threshold: 20, probability: 0.4, type: 'rest' },
        highDay: { threshold: 3, probability: 0.3, type: 'exploration' },
        inventoryFull: { threshold: 10, probability: 0.4, type: 'discovery' }
      },
      // 已生效加成
      buffs: { torch: false, trap: false },
      // AI 相关
      aiEnabled: false,
      aiBusy: false,
      aiConfig: { 
        baseURL: 'https://api.52vmy.cn/api/chat/spark', 
        model: 'spark',
        apiKey: ''
      },
      // 新增：底部Tab导航
      currentTab: 'survival',
      // 存档系统
      showSaveModal: false,
      saveSlots: [
        { data: null, date: null },
        { data: null, date: null },
        { data: null, date: null }
      ],
      autoSaveData: null,
      // 新增：地图系统
      showMapModal: false,
      currentLocationId: 'beach',
      // 地图模板库
      locationTemplates: [
        {
          id: 'beach',
          name: '海滩',
          icon: '🏖️',
          description: '一片开阔的海滩，可以看到远处的大海。这里有一些漂来的木材和贝壳。',
          resources: ['wood', 'shells'],
          actions: [
            { id: 'collect_wood', name: '收集木材', icon: '🪵', cost: 10, reward: { wood: 2 } },
            { id: 'collect_shells', name: '收集贝壳', icon: '🐚', cost: 8, reward: { shells: 1 } },
            { id: 'rest_beach', name: '海滩休息', icon: '😴', cost: 0, reward: { energy: 15 } }
          ]
        },
        {
          id: 'forest',
          name: '森林',
          icon: '🌲',
          description: '茂密的森林，树木参天。这里有丰富的木材和可能的食物。',
          resources: ['wood', 'food', 'berries'],
          actions: [
            { id: 'chop_wood', name: '砍伐木材', icon: '🪓', cost: 15, reward: { wood: 3 } },
            { id: 'gather_berries', name: '采集浆果', icon: '🍓', cost: 12, reward: { food: 2 } },
            { id: 'collect_herbs', name: '采集草药', icon: '🌿', cost: 10, reward: { herbs: 1 } }
          ]
        },
        {
          id: 'cave',
          name: '山洞',
          icon: '🕳️',
          description: '一个阴暗的山洞，里面有石头和可能的庇护所。',
          resources: ['stone', 'crystals'],
          actions: [
            { id: 'mine_stone', name: '开采石头', icon: '🪨', cost: 18, reward: { stone: 2 } },
            { id: 'find_crystals', name: '寻找水晶', icon: '💎', cost: 20, reward: { crystals: 1 } },
            { id: 'cave_shelter', name: '山洞避雨', icon: '🏠', cost: 5, reward: { energy: 10 } }
          ]
        },
        {
          id: 'river',
          name: '河流',
          icon: '🏞️',
          description: '清澈的河流，是获取淡水的理想地点。',
          resources: ['water', 'fish'],
          actions: [
            { id: 'collect_water', name: '收集淡水', icon: '💧', cost: 8, reward: { water: 3 } },
            { id: 'catch_fish', name: '捕鱼', icon: '🐟', cost: 15, reward: { food: 2 } },
            { id: 'wash_clothes', name: '清洗衣物', icon: '🧺', cost: 5, reward: { hygiene: 1 } }
          ]
        },
        {
          id: 'camp',
          name: '营地',
          icon: '🏕️',
          description: '你的临时营地，可以在这里休息和制作物品。',
          resources: ['safety', 'crafting'],
          actions: [
            { id: 'sleep', name: '睡觉休息', icon: '😴', cost: 0, reward: { energy: 30, hp: 5 } },
            { id: 'craft_items', name: '制作物品', icon: '🔨', cost: 10, reward: { crafting: 1 } },
            { id: 'organize_inventory', name: '整理背包', icon: '🎒', cost: 5, reward: { organization: 1 } }
          ]
        },
        {
          id: 'mountain',
          name: '山峰',
          icon: '⛰️',
          description: '高耸的山峰，可以俯瞰整个岛屿。',
          resources: ['stone', 'metal'],
          actions: [
            { id: 'mine_metal', name: '开采金属', icon: '⛏️', cost: 25, reward: { metal: 1 } },
            { id: 'scout_area', name: '侦察地形', icon: '🔭', cost: 15, reward: { scouting: 1 } }
          ]
        },
        {
          id: 'swamp',
          name: '沼泽',
          icon: '🐸',
          description: '潮湿的沼泽地，有独特的生物和资源。',
          resources: ['mud', 'mushrooms'],
          actions: [
            { id: 'collect_mud', name: '收集泥土', icon: '🪣', cost: 12, reward: { mud: 2 } },
            { id: 'gather_mushrooms', name: '采集蘑菇', icon: '🍄', cost: 18, reward: { mushrooms: 1 } }
          ]
        },
        {
          id: 'desert',
          name: '沙漠',
          icon: '🏜️',
          description: '广阔的沙漠，隐藏着古老的秘密。',
          resources: ['sand', 'cactus'],
          actions: [
            { id: 'collect_sand', name: '收集沙子', icon: '🏖️', cost: 10, reward: { sand: 3 } },
            { id: 'harvest_cactus', name: '收获仙人掌', icon: '🌵', cost: 20, reward: { cactus: 1 } }
          ]
        },
        {
          id: 'lake',
          name: '湖泊',
          icon: '🏞️',
          description: '宁静的湖泊，周围有丰富的植物资源。',
          resources: ['water', 'reeds'],
          actions: [
            { id: 'collect_water', name: '收集湖水', icon: '💧', cost: 8, reward: { water: 4 } },
            { id: 'gather_reeds', name: '采集芦苇', icon: '🌾', cost: 12, reward: { reeds: 2 } }
          ]
        }
      ],
      mapTiles: [],
      // 新增：建筑系统
      showBuildModal: false,
      buildings, // 从config/buildings.js引入
      // 新增：科技系统
      showTechModal: false,
      researchPoints: 100,
      techs, // 从config/techs.js引入
      
      // 瓦片地图相关数据
      tileMapData: [], // 瓦片地图数据
      tileMapExplored: [], // 已探索的瓦片
      tileMapRevealed: [], // 已发现的瓦片
      currentMapPosition: { x: 5, y: 5 }, // 当前地图位置
    }
  },
  computed: {
    currentLocation() {
      return this.mapTiles.find(tile => tile.id === this.currentLocationId) || null
    }
  },
  async onLoad() {
    // 【新增】初始化游戏管理器
    await this.initGameManager()
    
    this.loadState()
    await this.loadEvents()
    // 初始化地图（如果不存在或需要重新生成）
    this.initializeMap()
    // 初始化自动存档数据
    this.loadSaveSlots()
    // 加载AI配置
    try {
      const raw = uni.getStorageSync('textAIConfig')
      if (raw) {
        const cfg = JSON.parse(raw)
        this.aiConfig = { ...this.aiConfig, ...cfg }
        aiService.setConfig(this.aiConfig)
      }
    } catch (e) {}
    // 加载AI开关状态
    try {
      const aiEnabled = uni.getStorageSync('textSurvivalAIEnabled')
      if (aiEnabled !== null && aiEnabled !== undefined) {
        this.aiEnabled = !!aiEnabled
      }
    } catch (e) {}
    // 确保AI服务使用最新配置
    aiService.setConfig(this.aiConfig)
    if (this.logs.length === 0) this.pushLog('第 1 天开始。你在岛屿北侧的海滩上。')
    this.refreshOptions()
    // 初始化显示文本
    this.displayText = this.sceneText
    this.typeText(this.sceneText)
    
    // 初始化瓦片地图
    this.initializeTileMap()
  },
  methods: {
    // ==================== 游戏管理器适配层 ====================
    
    /**
     * 初始化游戏管理器
     */
    async initGameManager() {
      try {
        // 尝试从本地加载游戏状态
        const savedState = gameManager.loadState()
        
        if (savedState) {
          console.log('[GameManager] 加载已保存的游戏状态')
          this.syncStateFromManager(savedState)
        } else {
          console.log('[GameManager] 开始新游戏')
          gameManager.startNewGame('normal')
          this.syncStateFromManager(gameManager.getState())
        }
        
        // 加载每日一言
        this.todayQuote = await dailyQuote.getTodayQuote(this.day)
        console.log('[GameManager] 每日一言:', this.todayQuote)
        
      } catch (error) {
        console.error('[GameManager] 初始化失败:', error)
      }
    },
    
    /**
     * 从游戏管理器同步状态到Vue组件
     */
    syncStateFromManager(state) {
      this.hp = state.hp
      this.hunger = state.hunger
      this.energy = state.energy
      this.day = state.day
      this.thirst = state.thirst
      this.sanity = state.sanity
      this.temperature = state.temperature
      
      // 同步物品栏（合并现有和新的）
      this.inventory = {
        ...this.inventory,
        ...state.inventory
      }
      
      console.log('[GameManager] 状态已同步:', {
        hp: this.hp,
        hunger: this.hunger,
        energy: this.energy,
        day: this.day,
        thirst: this.thirst,
        sanity: this.sanity
      })
    },
    
    /**
     * 将Vue状态同步回游戏管理器
     */
    syncStateToManager() {
      const state = gameManager.getState()
      state.hp = this.hp
      state.hunger = this.hunger
      state.energy = this.energy
      state.day = this.day
      state.thirst = this.thirst
      state.sanity = this.sanity
      state.inventory = { ...this.inventory }
      gameManager.saveState()
    },
    
    /**
     * 获取状态等级描述
     */
    getStatusLevel(value) {
      if (value >= 80) return { text: '优秀', color: '#10b981' }
      if (value >= 60) return { text: '良好', color: '#3b82f6' }
      if (value >= 40) return { text: '一般', color: '#f59e0b' }
      if (value >= 20) return { text: '较差', color: '#ef4444' }
      return { text: '危险', color: '#dc2626' }
    },
    
    /**
     * 【新增】获取游戏技能列表
     */
    getGameSkills() {
      const state = gameManager.getState()
      const skillIcons = {
        gathering: '🌿',
        hunting: '🏹',
        crafting: '🔨',
        survival: '🏕️',
        exploration: '🗺️'
      }
      
      const skillNames = {
        gathering: '采集',
        hunting: '狩猎',
        crafting: '制作',
        survival: '生存',
        exploration: '探索'
      }
      
      const skills = []
      for (const [key, skill] of Object.entries(state.skills)) {
        skills.push({
          key,
          icon: skillIcons[key],
          name: skillNames[key],
          level: skill.level,
          exp: skill.exp,
          nextLevelExp: skill.nextLevelExp,
          bonus: `效率 +${skill.level * 10}%`
        })
      }
      
      return skills
    },
    
    /**
     * 【新增】获取已解锁的结局
     */
    getAchievedEndings() {
      try {
        const achievedEndings = JSON.parse(uni.getStorageSync('achievedEndings') || '[]')
        return achievedEndings
      } catch (error) {
        return []
      }
    },
    
    /**
     * 【新增】获取结局图标
     */
    getEndingIcon(endingId) {
      const icons = {
        'rescued': '🚁',
        'selfMade': '🛶',
        'islandKing': '🏝️',
        'scientist': '🔬',
        'wildman': '🐾',
        'despair': '💀',
        'mystery': '⚡'
      }
      return icons[endingId] || '🏆'
    },
    
    /**
     * 【新增】获取结局标题
     */
    getEndingTitle(endingId) {
      const ending = gameManager.getEndingInfo(endingId)
      return ending ? ending.title : '未知结局'
    },
    
    // ==================== 原有方法 ====================
    
    // 打字机效果
    typeText(text, callback) {
      // 清除之前的定时器
      if (this.typeTimer) {
        clearInterval(this.typeTimer)
      }
      
      this.isTyping = true
      this.displayText = ''
      let index = 0
      this.typeTimer = setInterval(() => {
        if (index < text.length) {
          this.displayText += text[index]
          index++
        } else {
          clearInterval(this.typeTimer)
          this.typeTimer = null
          this.isTyping = false
          if (callback) callback()
        }
      }, 50)
    },
    // 显示特效
    showSceneEffect(type, duration = 1000) {
      this.effectType = type
      this.showEffect = true
      setTimeout(() => {
        this.showEffect = false
      }, duration)
    },
    // 场景动画
    animateScene() {
      this.sceneAnimating = true
      setTimeout(() => {
        this.sceneAnimating = false
      }, 500)
    },
    // 播放音效（模拟）
    playSound(type) {
      // 这里可以添加真实的音效播放
      console.log(`播放音效: ${type}`)
    },
    // 获取游戏状态
    getGameState() {
      return {
        hp: this.hp,
        hunger: this.hunger,
        energy: this.energy,
        day: this.day,
        inventory: this.inventory,
        buffs: this.buffs,
        sceneText: this.sceneText
      }
    },
    async loadEvents() {
      try {
        // H5/小程序: 使用相对路径加载 static 下的 JSON
        const res = await fetch('/static/text-survival/events.json')
        const json = await res.json()
        this.events = json
      } catch (e) {
        // 回退到内置空集
        this.events = this.events || {}
      }
    },
    // 检查自动事件触发条件
    checkAutoEvents() {
      // 检查各种触发条件
      const triggers = []
      
      if (this.hp <= this.eventTriggers.lowHealth.threshold) {
        triggers.push({ ...this.eventTriggers.lowHealth, name: 'lowHealth' })
      }
      if (this.hunger <= this.eventTriggers.lowHunger.threshold) {
        triggers.push({ ...this.eventTriggers.lowHunger, name: 'lowHunger' })
      }
      if (this.energy <= this.eventTriggers.lowEnergy.threshold) {
        triggers.push({ ...this.eventTriggers.lowEnergy, name: 'lowEnergy' })
      }
      if (this.day >= this.eventTriggers.highDay.threshold) {
        triggers.push({ ...this.eventTriggers.highDay, name: 'highDay' })
      }
      
      // 检查背包是否满了
      const totalItems = Object.values(this.inventory).reduce((sum, val) => sum + val, 0)
      if (totalItems >= this.eventTriggers.inventoryFull.threshold) {
        triggers.push({ ...this.eventTriggers.inventoryFull, name: 'inventoryFull' })
      }
      
      // 随机触发一个事件
      if (triggers.length > 0 && Math.random() < this.autoEventProbability) {
        const selectedTrigger = triggers[Math.floor(Math.random() * triggers.length)]
        this.triggerAutoEvent(selectedTrigger)
      }
    },
    
    // 触发自动事件
    async triggerAutoEvent(trigger) {
      if (this.aiEnabled && !this.aiBusy) {
        // 使用AI生成事件
        await this.generateContextualAIEvent(trigger)
      } else {
        // 使用预设事件
        this.triggerPresetEvent(trigger)
      }
    },
    
    // 生成上下文相关的AI事件
    async generateContextualAIEvent(trigger) {
      this.aiBusy = true
      try {
        const contextPrompt = this.buildContextPrompt(trigger)
        const evt = await aiService.generateEvent({
          ...this.getGameState(),
          contextPrompt
        })
        
        // 添加AI标识
        evt.isAI = true
        evt.aiTag = 'AI生成'
        
        this.currentEvent = evt
        this.currentEventId = evt.id
        this.showChoice = true
        this.pushLog(`自动触发${trigger.type}事件：${evt.scene.slice(0, 30)}...`)
        this.saveState()
      } catch (e) {
        console.error('AI事件生成失败:', e)
        this.triggerPresetEvent(trigger)
      } finally {
        this.aiBusy = false
      }
    },
    
    // 构建上下文提示
    buildContextPrompt(trigger) {
      const prompts = {
        medical: '你受伤了，需要医疗救助。生成一个关于治疗、寻找药物或处理伤口的生存事件。',
        survival: '你面临生存危机，需要食物和水。生成一个关于寻找食物、水源或生存资源的紧急事件。',
        rest: '你极度疲惫，需要休息。生成一个关于寻找安全休息地点或处理疲劳的事件。',
        exploration: '你已经在这个岛上生活了一段时间，是时候探索更远的地方了。生成一个关于新发现或冒险的事件。',
        discovery: '你的背包已经装满了，需要处理物品或发现新的存储方式。生成一个关于物品管理或新发现的事件。'
      }
      return prompts[trigger.type] || '生成一个适合当前情况的生存事件。'
    },
    
    // 触发预设事件
    triggerPresetEvent(trigger) {
      const eventMap = {
        medical: 'medical_emergency',
        survival: 'food_crisis',
        rest: 'exhaustion',
        exploration: 'new_discovery',
        discovery: 'inventory_management'
      }
      
      const eventId = eventMap[trigger.type] || 'random_event'
      this.openEvent(eventId)
    },
    openEvent(id) {
      const evt = this.events[id]
      if (!evt) { this.showChoice = false; return }
      this.currentEventId = id
      this.currentEvent = JSON.parse(JSON.stringify(evt))
      this.showChoice = true
      this.saveState()
    },
    onSelectOption(opt) {
      this.showChoice = false
      if (opt && opt.effects) this.applyEffects(opt.effects, `你选择了"${opt.label}"。`)
      // 随机示例：apply开头的逻辑在这里处理
      if (this.currentEventId === 'rng_berry_outcome' && opt.next === 'apply_rng_berry') {
        const lucky = Math.random() < 0.5
        if (lucky) this.applyEffects({ hunger: +10 }, '运气不错，这些果子可以吃，你恢复了一些体力。')
        else this.applyEffects({ hp: -10 }, '不幸的是，你感觉不适，应该更谨慎一些。')
      }
      if (this.currentEventId === 'random_branch' && opt.next === 'apply_random') {
        const n = Math.random()
        if (n < 0.33) this.applyEffects({ hp: -8 }, '你不慎跌倒，擦伤了手臂。')
        else if (n < 0.66) this.applyEffects({ hunger: +8 }, '你捡到了一些干果。')
        else this.applyEffects({ energy: -8 }, '酷热让你步伐沉重。')
      }
      if (opt && opt.next) setTimeout(() => this.openEvent(opt.next), 300)
      
      // 检查是否触发自动事件
      setTimeout(() => {
        this.checkAutoEvents()
      }, 1000)
      
      this.saveState()
    },
    // 制作/背包
    openCrafting() { this.showCraft = true },
    craftItem(recipe) {
      // 检查前置条件
      if (!this.checkCraftPrerequisites(recipe)) {
        const missingPrereqs = this.getMissingCraftPrerequisites(recipe)
        uni.showToast({
          title: `需要先研究：${missingPrereqs.join('、')}`,
          icon: 'none',
          duration: 3000
        })
        return
      }
      
      // 检查资源
      const missingResources = this.checkCraftResources(recipe)
      if (missingResources.length > 0) {
        uni.showToast({
          title: `缺少材料：${missingResources.join('、')}`,
          icon: 'none',
          duration: 3000
        })
        return
      }
      
      // 扣除资源
      const need = recipe.requires || {}
      for (const k in need) this.inventory[k] -= need[k]
      
      // 显示制作成功提示
      this.showCraftNotification(recipe)
      
      // 应用效果（演示）
      if (recipe.id === 'bandage') this.applyEffects({ hp: +10 }, '你使用绷带处理了伤口。')
      if (recipe.id === 'torch') { this.buffs.torch = true; this.pushLog('你制作了火把，夜间探索更安全。') }
      if (recipe.id === 'trap') { this.buffs.trap = true; this.pushLog('你在林缘设置了简易陷阱。') }
      if (recipe.id === 'medicine_kit') { this.applyEffects({ hp: +30 }, '你制作了医疗包，生命值大幅恢复。') }
      if (recipe.id === 'water_filter') { this.buffs.waterFilter = true; this.pushLog('你制作了净水器，淡水产量增加。') }
      if (recipe.id === 'metal_knife') { this.buffs.metalKnife = true; this.pushLog('你制作了金属刀，采集效率大幅提升。') }
      if (recipe.id === 'advanced_medicine') { this.applyEffects({ hp: +50, energy: +30 }, '你制作了高级药品，生命和精力都得到恢复。') }
      
      this.saveState()
    },
    
    // 检查制作前置条件
    checkCraftPrerequisites(recipe) {
      if (!recipe.prerequisites || recipe.prerequisites.length === 0) {
        return true
      }
      
      for (const prereqId of recipe.prerequisites) {
        const prereqTech = this.techs.find(t => t.id === prereqId)
        if (!prereqTech || !prereqTech.completed) {
          return false
        }
      }
      return true
    },
    
    // 获取缺失的制作前置条件
    getMissingCraftPrerequisites(recipe) {
      if (!recipe.prerequisites || recipe.prerequisites.length === 0) {
        return []
      }
      
      const missing = []
      for (const prereqId of recipe.prerequisites) {
        const prereqTech = this.techs.find(t => t.id === prereqId)
        if (!prereqTech || !prereqTech.completed) {
          missing.push(prereqTech ? prereqTech.name : prereqId)
        }
      }
      return missing
    },
    
    // 检查制作资源
    checkCraftResources(recipe) {
      const missing = []
      const need = recipe.requires || {}
      for (const k in need) {
        if ((this.inventory[k] || 0) < need[k]) {
          missing.push(`${this.translateResource(k)}×${need[k]}`)
        }
      }
      return missing
    },
    
    // 显示制作成功提示
    showCraftNotification(recipe) {
      const message = `制作成功: ${recipe.name}`
      
      // 显示提示
      uni.showToast({
        title: message,
        icon: 'success',
        duration: 2000,
        position: 'center'
      })
      
      // 添加制作特效
      this.showCraftEffect(recipe.name)
    },
    
    // 显示制作特效
    showCraftEffect(itemName) {
      console.log(`制作特效: ${itemName}`)
      // 这里可以添加更丰富的制作特效
    },
    // 资源拾取（示例：可由事件effects扩展）
    addResource(key, amount = 1, reason = '') {
      this.inventory[key] = (this.inventory[key] || 0) + amount
      if (reason) this.pushLog(reason)
      
      // 显示物资收集提示
      this.showResourceNotification(key, amount)
      this.pushLog(`收集了 ${amount} 个${this.getResourceName(key)}`)
      this.saveState()
    },
    
    // 获取资源名称
    getResourceName(resource) {
      const resourceNames = {
        wood: '木材',
        stone: '石头',
        vine: '藤蔓',
        water: '淡水',
        metal: '金属',
        mud: '泥土',
        crystals: '水晶',
        herbs: '草药',
        mushrooms: '蘑菇',
        sand: '沙子',
        reeds: '芦苇',
        cactus: '仙人掌',
        shells: '贝壳'
      }
      return resourceNames[resource] || resource
    },
    
    // 添加新物品到背包
    addNewItem(itemName, amount = 1, reason = '') {
      this.inventory[itemName] = (this.inventory[itemName] || 0) + amount
      if (reason) this.pushLog(reason)
      
      // 显示新物品提示
      this.showResourceNotification(itemName, amount)
      this.saveState()
    },
    
    // 显示物资收集提示
    showResourceNotification(key, amount) {
      const resourceNames = {
        wood: '木材',
        stone: '石头', 
        vine: '藤蔓',
        water: '淡水'
      }
      
      const name = resourceNames[key] || key
      const message = `+${amount} ${name}`
      
      // 显示提示
      uni.showToast({
        title: message,
        icon: 'none',
        duration: 1500,
        position: 'center'
      })
      
      // 也可以添加更丰富的提示效果
      this.showFloatingText(message)
    },
    
    // 显示浮动文字效果
    showFloatingText(text) {
      // 创建浮动文字元素（如果需要更丰富的效果）
      console.log(`浮动文字: ${text}`)
    },
    // 基础效果应用（限定 0-100）
    applyEffects(delta, logText) {
      const clamp = (v) => Math.max(0, Math.min(100, v))
      const before = { hp: this.hp, hunger: this.hunger, energy: this.energy }
      
      // 禁用操作防止重复点击
      this.isActionDisabled = true
      
      // 支持简单资源变更：resources: { wood:+1 }
      if (delta.resources) {
        Object.keys(delta.resources).forEach(k => {
          // 检查是否是中文物品名（新物品）
          if (/[\u4e00-\u9fa5]/.test(k)) {
            this.addNewItem(k, delta.resources[k])
          } else {
            this.addResource(k, delta.resources[k])
          }
        })
      }
      
      // 应用状态变化
      const hpChange = delta.hp || 0
      const hungerChange = delta.hunger || 0
      const energyChange = delta.energy || 0
      
      this.hunger = clamp(this.hunger + hungerChange)
      this.energy = clamp(this.energy + energyChange)
      if (typeof delta.hp === 'number') this.hp = clamp(this.hp + hpChange)
      
      // 饥饿和精力过低会影响生命值
      if (this.hunger <= 10) this.hp = clamp(this.hp - 5)
      if (this.energy <= 10) this.hp = clamp(this.hp - 5)
      
      // 播放相应的音效和特效
      if (hpChange > 0) {
        this.playSound('heal')
        this.showSceneEffect('heal')
      } else if (hpChange < 0) {
        this.playSound('damage')
        this.showSceneEffect('damage')
      }
      
      if (hungerChange > 0) {
        this.playSound('eat')
        this.showSceneEffect('eat')
      }
      
      if (energyChange > 0) {
        this.playSound('rest')
        this.showSceneEffect('rest')
      }
      
      // 更新场景描述
      this.updateScene()
      
      // 打字机效果显示日志
      if (logText) {
        this.typeText(logText, () => {
          this.pushLog(`状态变化: 生命 ${before.hp}→${this.hp} | 饥饿 ${before.hunger}→${this.hunger} | 精力 ${before.energy}→${this.energy}`)
          this.checkGameOver()
          this.saveState()
          // 重新启用操作
          setTimeout(() => {
            this.isActionDisabled = false
          }, 1000)
        })
      } else {
      this.pushLog(`状态变化: 生命 ${before.hp}→${this.hp} | 饥饿 ${before.hunger}→${this.hunger} | 精力 ${before.energy}→${this.energy}`)
        this.checkGameOver()
        this.saveState()
        setTimeout(() => {
          this.isActionDisabled = false
        }, 1000)
      }
    },
    nextDay() {
      this.day += 1
      this.applyEffects({ hunger: -10, energy: +10 }, `夜幕降临，你用简易庇护所过夜。第 ${this.day} 天清晨到来。`)
      this.saveState()
    },
    updateScene() {
      let newSceneText = ''
      if (this.hunger < 20) {
        newSceneText = '你的胃在剧烈抗议，饥饿感如潮水般涌来。你需要尽快寻找食物，否则将面临生命危险。'
        this.playSound('hunger')
        this.showSceneEffect('hunger')
      } else if (this.energy < 20) {
        newSceneText = '你感到极度乏力，每一步都如千斤重担。疲惫让你无法集中注意力，急需休息。'
        this.playSound('tired')
        this.showSceneEffect('tired')
      } else if (this.hp < 40) {
        newSceneText = '身体的伤势让你行动缓慢，疼痛时刻提醒着你的脆弱。每一步都要格外小心。'
        this.playSound('injured')
        this.showSceneEffect('injured')
      } else if (this.hp < 70) {
        newSceneText = '海风与森林的气息交织，你保持着谨慎与希望。虽然有些疲惫，但仍有继续前进的勇气。'
      } else {
        newSceneText = '海风与森林的气息交织，你仍旧保持着谨慎与希望。身体状态良好，可以继续探索。'
      }
      
      if (newSceneText !== this.sceneText) {
        this.sceneText = newSceneText
        this.animateScene()
        this.typeText(newSceneText)
      }
    },
    checkGameOver() {
      if (this.hp <= 0) {
        this.hp = 0
        this.pushLog('你倒下了……也许换一种方式再来过。')
        uni.showModal({ title: '游戏结束', content: `你在第 ${this.day} 天倒下了`, showCancel: false })
      }
    },
    // 日志
    pushLog(text) {
      const ts = new Date().toLocaleTimeString('zh-CN', { hour: '2-digit', minute: '2-digit' })
      this.logs.unshift(`[${ts}] ${text}`)
      if (this.logs.length > 50) this.logs.splice(50)
    },
    // 存档
    saveState() {
      const state = {
        hp: this.hp,
        hunger: this.hunger,
        energy: this.energy,
        day: this.day,
        logs: this.logs,
        sceneText: this.sceneText,
        currentEventId: this.currentEventId,
        inventory: this.inventory,
        lastUrgentDay: this.lastUrgentDay,
        buffs: this.buffs,
        currentLocationId: this.currentLocationId,
        mapTiles: this.mapTiles,
        buildings: this.buildings,
        techs: this.techs,
        researchPoints: this.researchPoints,
        tileMapExplored: this.tileMapExplored,
        tileMapRevealed: this.tileMapRevealed,
        currentMapPosition: this.currentMapPosition,
        date: new Date().toLocaleString('zh-CN')
      }
      uni.setStorageSync('textSurvivalState', JSON.stringify(state))
      
      // 同时保存自动存档
      uni.setStorageSync('autoSave', state)
      this.autoSaveData = {
        data: state,
        date: state.date
      }
    },
    loadState() {
      try {
        const raw = uni.getStorageSync('textSurvivalState')
        if (raw) {
          const s = JSON.parse(raw)
          this.hp = s.hp; this.hunger = s.hunger; this.energy = s.energy; this.day = s.day
          this.logs = s.logs || []; this.sceneText = s.sceneText || this.sceneText
          this.currentEventId = s.currentEventId || this.currentEventId
          this.inventory = s.inventory || this.inventory
          this.lastUrgentDay = s.lastUrgentDay || 0
          this.buffs = s.buffs || this.buffs
          
          // 加载瓦片地图数据
          this.tileMapExplored = s.tileMapExplored || Array(100).fill(false)
          this.tileMapRevealed = s.tileMapRevealed || Array(100).fill(false)
          this.currentMapPosition = s.currentMapPosition || { x: 5, y: 5 }
        }
      } catch (e) {}
    },
    resetGame() {
      uni.showModal({
        title: '重开确认', content: '确定要重新开始吗？当前进度将被覆盖。',
        success: (res) => {
          if (res.confirm) {
            this.hp = 100; this.hunger = 60; this.energy = 80; this.day = 1; this.logs = []
            this.sceneText = '你清晨醒来，潮湿的风从密林吹来。你需要寻找食物与安全的落脚点。'
            this.currentEventId = 'intro_beach'
            this.inventory = { wood: 0, stone: 0, vine: 0, water: 0 }
            this.buffs = { torch: false, trap: false } // Reset buffs on reset
            
            // 重新生成随机地图
            this.mapTiles = []
            this.generateRandomMap()
            
            this.pushLog('第 1 天开始。你在岛屿北侧的海滩上。')
            this.pushLog('每次重开游戏，岛屿的地形都会发生变化，探索新的可能性！')
            this.refreshOptions(); this.saveState()
          }
        }
      })
    },
    refreshOptions() {
      const currentLocation = this.currentLocation
      if (!currentLocation) {
        this.options = []
        return
      }
      
      // 根据当前位置显示不同的操作
      this.options = currentLocation.actions.map(action => ({
        label: `${action.icon} ${action.name}`,
        risk: action.cost > 15 ? '高' : action.cost > 10 ? '中' : '低',
        effect: () => this.performLocationAction(action)
      }))
    },
    choose(opt) { 
      try { 
        opt.effect() 
      } catch (e) {} 
      this.randomEvent()
      // 检查是否触发自动事件
      setTimeout(() => {
        this.checkAutoEvents()
      }, 1000)
      this.saveState() 
    },
    randomEvent() {
      if (Math.random() < 0.2) {
        const events = [
          () => this.applyEffects({ hp: -6 }, '突遇小型滑倒，你擦伤了膝盖。'),
          () => this.applyEffects({ hunger: +6 }, '你意外发现几枚可食用果仁。'),
          () => this.applyEffects({ energy: -6 }, '烈日消耗了你的体力。')
        ]
        const evt = events[Math.floor(Math.random() * events.length)]
        evt()
      }
    },
    toggleAI(e) {
      this.aiEnabled = !!(e?.detail?.value)
      // 保存AI开关状态到本地存储
      uni.setStorageSync('textSurvivalAIEnabled', this.aiEnabled)
      if (this.aiEnabled) {
        uni.showToast({ title: 'AI测试版已开启', icon: 'none' })
      } else {
        uni.showToast({ title: 'AI已关闭', icon: 'none' })
      }
    },
    openAIConfig() {
      uni.navigateTo({ url: '/pages/game/text-survival/ai-settings' })
    },
    async generateAIEvent() {
      if (!this.aiEnabled || this.aiBusy) return
      this.aiBusy = true
      
      console.log('开始生成AI事件...')
      console.log('AI配置:', this.aiConfig)
      
      try {
        console.log('检查AI服务可用性...')
        const available = await aiService.isAvailable()
        console.log('AI服务可用性:', available)
        
        if (!available) {
          throw new Error('AI服务不可用，请检查网络连接或API配置')
        }
        
        console.log('开始生成事件，游戏状态:', {
          hp: this.hp,
          hunger: this.hunger,
          energy: this.energy,
          day: this.day,
          inventory: this.inventory,
          buffs: this.buffs,
          sceneText: this.sceneText
        })
        
        const evt = await aiService.generateEvent({
          hp: this.hp,
          hunger: this.hunger,
          energy: this.energy,
          day: this.day,
          inventory: this.inventory,
          buffs: this.buffs,
          sceneText: this.sceneText
        })
        
        console.log('AI生成的事件:', evt)
        
        // 添加AI标识
        evt.isAI = true
        evt.aiTag = 'AI测试'
        
        // 打开AI事件
        this.currentEvent = evt
        this.currentEventId = evt.id
        this.showChoice = true
        this.pushLog('AI事件（测试版）已生成，请注意其稳定性与偏差。')
        this.saveState()
        
        console.log('AI事件生成成功')
      } catch (e) {
        console.error('AI事件生成失败:', e)
        console.error('错误详情:', e.message, e.stack)
        uni.showToast({ 
          title: e?.message || '生成失败', 
          icon: 'none',
          duration: 3000
        })
      } finally {
        this.aiBusy = false
        console.log('AI生成流程结束')
      }
    },
    
    // 新增：底部Tab导航方法
    switchTab(tab) {
      this.currentTab = tab
      
      switch(tab) {
        case 'map':
          this.openMapModal()
          break
        case 'build':
          this.openBuildModal()
          break
        case 'tech':
          this.openTechModal()
          break
        case 'inventory':
          this.openCrafting()
          break
        case 'survival':
        default:
          // 生存模式，不需要额外操作
          break
      }
    },
    
    // 新增：地图系统方法
    initializeMap() {
      // 检查是否已有地图数据
      if (this.mapTiles.length > 0) {
        return // 如果已有地图数据，不重新生成
      }
      
      // 生成随机地图
      this.generateRandomMap()
    },
    
    // 生成随机地图
    generateRandomMap() {
      // 创建3x3网格位置
      const positions = [
        { x: 0, y: 0 }, { x: 1, y: 0 }, { x: 2, y: 0 },
        { x: 0, y: 1 }, { x: 1, y: 1 }, { x: 2, y: 1 },
        { x: 0, y: 2 }, { x: 1, y: 2 }, { x: 2, y: 2 }
      ]
      
      // 随机打乱位置
      const shuffledPositions = [...positions].sort(() => Math.random() - 0.5)
      
      // 选择9个不同的地点类型
      const selectedLocations = this.selectRandomLocations(9)
      
      // 生成地图瓦片
      this.mapTiles = selectedLocations.map((location, index) => {
        const position = shuffledPositions[index]
        const isStartingLocation = location.id === 'beach' || location.id === 'camp'
        
        return {
          ...location,
          position: position,
          explored: isStartingLocation,
          discovered: isStartingLocation,
          flipping: false,
          switching: false,
          exploreCost: isStartingLocation ? 0 : this.generateExploreCost(location.id)
        }
      })
      
      // 设置起始位置
      const beachTile = this.mapTiles.find(tile => tile.id === 'beach')
      if (beachTile) {
        this.currentLocationId = beachTile.id
      }
      
      console.log('生成随机地图:', this.mapTiles)
      console.log('地图瓦片数量:', this.mapTiles.length)
      console.log('当前地图状态:', this.mapTiles.map(tile => ({
        id: tile.id,
        name: tile.name,
        discovered: tile.discovered,
        explored: tile.explored
      })))
    },
    
    // 选择随机地点
    selectRandomLocations(count) {
      const availableLocations = [...this.locationTemplates]
      const selected = []
      
      // 确保包含起始地点
      const beachIndex = availableLocations.findIndex(loc => loc.id === 'beach')
      if (beachIndex !== -1) {
        selected.push(availableLocations.splice(beachIndex, 1)[0])
      }
      
      const campIndex = availableLocations.findIndex(loc => loc.id === 'camp')
      if (campIndex !== -1) {
        selected.push(availableLocations.splice(campIndex, 1)[0])
      }
      
      // 随机选择剩余地点
      while (selected.length < count && availableLocations.length > 0) {
        const randomIndex = Math.floor(Math.random() * availableLocations.length)
        selected.push(availableLocations.splice(randomIndex, 1)[0])
      }
      
      return selected
    },
    
    // 生成探索成本
    generateExploreCost(locationId) {
      const baseCosts = {
        'beach': 0,
        'camp': 0,
        'forest': 20,
        'cave': 25,
        'river': 15,
        'mountain': 35,
        'swamp': 30,
        'desert': 40,
        'lake': 20
      }
      
      const baseCost = baseCosts[locationId] || 25
      // 添加随机变化 ±5
      const variation = Math.floor(Math.random() * 11) - 5
      return Math.max(10, baseCost + variation)
    },
    
    openMapModal() {
      this.showMapModal = true
    },
    
    closeMapModal() {
      this.showMapModal = false
    },
    
    // 位置切换动画
    animateLocationSwitch(tile) {
      // 添加切换动画类
      tile.switching = true
      
      // 播放切换音效
      this.playSound('move')
      
      // 显示切换特效
      this.showSceneEffect('move')
      
      // 动画持续时间
      setTimeout(() => {
        // 更新位置
        this.currentLocationId = tile.id
        
        // 显示成功提示
        uni.showToast({
          title: `移动到：${tile.name}`,
          icon: 'success',
          duration: 2000
        })
        this.pushLog(`移动到：${tile.name}`)
        
        // 刷新选项
        this.refreshOptions()
        
        // 移除动画类
        tile.switching = false
        
        // 关闭地图弹窗
        this.closeMapModal()
        
        // 保存状态
        this.saveState()
      }, 600)
    },
    
    exploreTile(tile) {
      // 如果已经探索过，直接移动到该位置
      if (tile.explored) {
        if (tile.id === this.currentLocationId) {
          uni.showToast({
            title: '你已经在当前位置',
            icon: 'none',
            duration: 2000
          })
          return
        }
        
        // 添加位置切换动画
        this.animateLocationSwitch(tile)
        return
      }
      
      // 检查精力是否足够进行任何探索
      if (this.energy < 10) {
        uni.showToast({
          title: `精力耗尽，无法探索（当前：${this.energy}）`,
          icon: 'none',
          duration: 3000
        })
        this.pushLog(`精力耗尽，无法进行探索（当前精力：${this.energy}）`)
        return
      }
      
      // 如果已经发现但未探索，检查精力后探索
      if (tile.discovered && !tile.explored) {
        // 检查是否有足够的精力进行探索
        if (this.energy < 10) { // 探索已发现地点需要少量精力
          uni.showToast({
            title: `精力不足，需要10精力（当前：${this.energy}）`,
            icon: 'none',
            duration: 3000
          })
          this.pushLog(`尝试探索${tile.name}失败：精力不足（需要10，当前${this.energy}）`)
          return
        }
        this.exploreLocation(tile)
        return
      }
      
      // 如果未发现，先发现再探索
      if (!tile.discovered) {
        this.discoverLocation(tile)
      }
    },
    
    // 发现新地点
    discoverLocation(tile) {
      if (this.energy < tile.exploreCost) {
        // 显示精力不足提示
        uni.showToast({
          title: `精力不足，需要${tile.exploreCost}精力（当前：${this.energy}）`,
          icon: 'none',
          duration: 3000
        })
        
        // 记录到日志
        this.pushLog(`尝试探索${tile.name}失败：精力不足（需要${tile.exploreCost}，当前${this.energy}）`)
        return
      }
      
      // 消耗精力
      this.energy -= tile.exploreCost
      
      // 开始翻转动画
      tile.flipping = true
      
      uni.showToast({
        title: `发现了新区域：${tile.name}`,
        icon: 'success',
        duration: 2000
      })
      this.pushLog(`发现了新区域：${tile.name}，消耗精力${tile.exploreCost}`)
      
      // 翻转动画完成后自动探索
      setTimeout(() => {
        tile.discovered = true
        tile.flipping = false
        this.exploreLocation(tile)
      }, 300)
      
      this.saveState()
    },
    
    // 探索地点
    exploreLocation(tile) {
      tile.explored = true
      
      uni.showToast({
        title: `探索了区域：${tile.name}`,
        icon: 'success',
        duration: 2000
      })
      this.pushLog(`探索了区域：${tile.name}`)
      
      // 自动切换到新探索的位置
      this.currentLocationId = tile.id
      this.refreshOptions()
      this.closeMapModal()
      
      this.saveState()
    },
    
    // 新增：建筑系统方法
    openBuildModal() {
      this.showBuildModal = true
    },
    
    closeBuildModal() {
      this.showBuildModal = false
    },
    
    buildBuilding(building) {
      // 检查是否已建造
      if (building.built) {
        // 检查是否可以升级
        if (building.level < building.maxLevel) {
          this.upgradeBuilding(building)
        } else {
        uni.showToast({
            title: '建筑已达到最高等级',
          icon: 'none',
          duration: 2000
          })
        }
        return
      }
      
      // 检查前置条件
      if (!this.checkBuildingPrerequisites(building)) {
        const missingPrereqs = this.getMissingPrerequisites(building)
        uni.showToast({
          title: `需要先建造：${missingPrereqs.join('、')}`,
          icon: 'none',
          duration: 3000
        })
        return
      }
      
      // 检查资源是否足够
      const missingResources = this.checkBuildingResources(building)
      if (missingResources.length > 0) {
        uni.showToast({
          title: `缺少材料：${missingResources.join('、')}`,
          icon: 'none',
          duration: 3000
        })
        return
      }
      
        // 扣除资源
        for (const resource in building.cost) {
          this.inventory[resource] -= building.cost[resource]
        }
        
        building.built = true
        uni.showToast({
          title: `建造了${building.name}`,
          icon: 'success',
          duration: 2000
        })
        this.pushLog(`建造了${building.name}`)
        this.saveState()
    },
    
    // 升级建筑
    upgradeBuilding(building) {
      if (!building.upgradeCost) {
        uni.showToast({
          title: '该建筑无法升级',
          icon: 'none',
          duration: 2000
        })
        return
      }
      
      // 检查升级资源
      const missingResources = this.checkUpgradeResources(building)
      if (missingResources.length > 0) {
        uni.showToast({
          title: `升级缺少材料：${missingResources.join('、')}`,
          icon: 'none',
          duration: 3000
        })
        return
      }
      
      // 扣除升级资源
      for (const resource in building.upgradeCost) {
        this.inventory[resource] -= building.upgradeCost[resource]
      }
      
      building.level += 1
      uni.showToast({
        title: `${building.name}升级到${building.level}级`,
        icon: 'success',
        duration: 2000
      })
      this.pushLog(`${building.name}升级到${building.level}级`)
      this.saveState()
    },
    
    // 检查建筑前置条件
    checkBuildingPrerequisites(building) {
      if (!building.prerequisites || building.prerequisites.length === 0) {
        return true
      }
      
      for (const prereqId of building.prerequisites) {
        const prereqBuilding = this.buildings.find(b => b.id === prereqId)
        if (!prereqBuilding || !prereqBuilding.built) {
          return false
        }
      }
      return true
    },
    
    // 获取缺失的前置条件
    getMissingPrerequisites(building) {
      if (!building.prerequisites || building.prerequisites.length === 0) {
        return []
      }
      
      const missing = []
      for (const prereqId of building.prerequisites) {
        const prereqBuilding = this.buildings.find(b => b.id === prereqId)
        if (!prereqBuilding || !prereqBuilding.built) {
          missing.push(prereqBuilding ? prereqBuilding.name : prereqId)
        }
      }
      return missing
    },
    
    // 检查建筑资源
    checkBuildingResources(building) {
      const missing = []
      for (const resource in building.cost) {
        if (this.inventory[resource] < building.cost[resource]) {
          missing.push(`${this.translateResource(resource)}×${building.cost[resource]}`)
        }
      }
      return missing
    },
    
    // 检查升级资源
    checkUpgradeResources(building) {
      const missing = []
      for (const resource in building.upgradeCost) {
        if (this.inventory[resource] < building.upgradeCost[resource]) {
          missing.push(`${this.translateResource(resource)}×${building.upgradeCost[resource]}`)
        }
      }
      return missing
    },
    
    // 翻译资源名称
    translateResource(resource) {
      const map = {
        wood: '木材',
        stone: '石头',
        vine: '藤蔓',
        water: '淡水',
        metal: '金属',
        mud: '泥土',
        crystals: '水晶',
        herbs: '草药',
        mushrooms: '蘑菇',
        sand: '沙子',
        reeds: '芦苇',
        cactus: '仙人掌',
        shells: '贝壳'
      }
      return map[resource] || resource
    },
    
    // 格式化建筑成本
    formatBuildingCost(cost) {
      if (!cost) return '无'
      return Object.keys(cost).map(k => `${this.translateResource(k)}×${cost[k]}`).join('、')
    },
    
    // 格式化前置条件
    formatPrerequisites(prerequisites) {
      if (!prerequisites || prerequisites.length === 0) return '无'
      return prerequisites.map(id => {
        const building = this.buildings.find(b => b.id === id)
        return building ? building.name : id
      }).join('、')
    },
    
    // 格式化科技前置条件
    formatTechPrerequisites(prerequisites) {
      if (!prerequisites || prerequisites.length === 0) return '无'
      return prerequisites.map(id => {
        const tech = this.techs.find(t => t.id === id)
        return tech ? tech.name : id
      }).join('、')
    },
    
    // 新增：科技系统方法
    openTechModal() {
      this.showTechModal = true
    },
    
    closeTechModal() {
      this.showTechModal = false
    },
    
    startResearch(tech) {
      // 检查是否已完成
      if (tech.completed) {
        uni.showToast({
          title: '科技已完成',
          icon: 'none',
          duration: 2000
        })
        return
      }
      
      // 检查是否正在研究
      if (tech.researching) {
        uni.showToast({
          title: '正在研究中',
          icon: 'none',
          duration: 2000
        })
        return
      }
      
      // 检查前置条件
      if (!this.checkTechPrerequisites(tech)) {
        const missingPrereqs = this.getMissingTechPrerequisites(tech)
        uni.showToast({
          title: `需要先研究：${missingPrereqs.join('、')}`,
          icon: 'none',
          duration: 3000
        })
        return
      }
      
      // 检查研究点数
      if (this.researchPoints < tech.cost) {
        uni.showToast({
          title: `研究点数不足，需要${tech.cost}点（当前：${this.researchPoints}）`,
          icon: 'none',
          duration: 3000
        })
        return
      }
      
      // 开始研究
      tech.researching = true
      this.researchPoints -= tech.cost
      
      uni.showToast({
        title: `开始研究${tech.name}`,
        icon: 'success',
        duration: 2000
      })
      this.pushLog(`开始研究${tech.name}`)
      
      // 模拟研究时间（实际游戏中可以设置研究时间）
      setTimeout(() => {
        tech.researching = false
        tech.completed = true
        uni.showToast({
          title: `${tech.name}研究完成`,
          icon: 'success',
          duration: 2000
        })
        this.pushLog(`${tech.name}研究完成`)
        this.saveState()
      }, 3000) // 3秒研究时间
      
      this.saveState()
    },
    
    // 检查科技前置条件
    checkTechPrerequisites(tech) {
      if (!tech.prerequisites || tech.prerequisites.length === 0) {
        return true
      }
      
      for (const prereqId of tech.prerequisites) {
        const prereqTech = this.techs.find(t => t.id === prereqId)
        if (!prereqTech || !prereqTech.completed) {
          return false
        }
      }
      return true
    },
    
    // 获取缺失的科技前置条件
    getMissingTechPrerequisites(tech) {
      if (!tech.prerequisites || tech.prerequisites.length === 0) {
        return []
      }
      
      const missing = []
      for (const prereqId of tech.prerequisites) {
        const prereqTech = this.techs.find(t => t.id === prereqId)
        if (!prereqTech || !prereqTech.completed) {
          missing.push(prereqTech ? prereqTech.name : prereqId)
        }
      }
      return missing
    },
    
    // 新增：执行地点操作
    performLocationAction(action) {
      if (this.energy < action.cost) {
        uni.showToast({
          title: '精力不足',
          icon: 'none',
          duration: 2000
        })
        return
      }
      
      // 消耗精力
      this.energy -= action.cost
      
      // 应用奖励
      for (const resource in action.reward) {
        if (resource === 'energy') {
          this.energy = Math.min(100, this.energy + action.reward[resource])
        } else if (resource === 'hp') {
          this.hp = Math.min(100, this.hp + action.reward[resource])
        } else if (resource === 'hunger') {
          this.hunger = Math.min(100, this.hunger + action.reward[resource])
        } else {
          // 其他资源
          this.inventory[resource] = (this.inventory[resource] || 0) + action.reward[resource]
        }
      }
      
      // 显示结果
      let rewardText = ''
      for (const resource in action.reward) {
        if (action.reward[resource] > 0) {
          rewardText += `+${action.reward[resource]} ${this.getResourceName(resource)} `
        }
      }
      
      uni.showToast({
        title: `执行了${action.name}`,
        icon: 'success',
        duration: 2000
      })
      
      this.pushLog(`在${this.currentLocation.name}执行了${action.name}，获得：${rewardText.trim()}`)
      
      // ========== 【新增】技能升级系统 ==========
      this.addSkillExpByAction(action)
      
      // 同步状态到game-manager
      this.syncStateToManager()
      // =========================================
      
      this.saveState()
    },
    
    /**
     * 【新增】根据操作添加技能经验
     */
    addSkillExpByAction(action) {
      const skillMap = {
        'gather': 'gathering',
        'collect': 'gathering',
        'mine': 'gathering',
        'hunt': 'hunting',
        'fish': 'hunting',
        'catch': 'hunting',
        'build': 'crafting',
        'craft': 'crafting',
        'cook': 'survival',
        'sleep': 'survival',
        'rest': 'survival'
      }
      
      // 查找匹配的技能
      let matchedSkill = null
      for (const [keyword, skill] of Object.entries(skillMap)) {
        if (action.id.toLowerCase().includes(keyword) || action.name.includes(keyword)) {
          matchedSkill = skill
          break
        }
      }
      
      if (matchedSkill) {
        const expGained = 10 + Math.floor(Math.random() * 5) // 10-14 经验
        gameManager.addSkillExp(matchedSkill, expGained)
        
        // 获取技能中文名
        const skillNames = {
          'gathering': '采集',
          'hunting': '狩猎',
          'crafting': '制作',
          'survival': '生存',
          'exploration': '探索'
        }
        
        // 检查是否升级
        const gameState = gameManager.getState()
        const currentSkill = gameState.skills[matchedSkill]
        if (currentSkill) {
          this.pushLog(`[技能] ${skillNames[matchedSkill]} +${expGained}经验 (${currentSkill.exp}/${currentSkill.nextLevelExp})`)
          
          // 如果刚好升级，显示升级提示
          if (currentSkill.exp >= currentSkill.nextLevelExp) {
            uni.showToast({
              title: `${skillNames[matchedSkill]}技能升级！`,
              icon: 'success',
              duration: 2000
            })
            this.pushLog(`🎉 [技能升级] ${skillNames[matchedSkill]} Lv.${currentSkill.level - 1} → Lv.${currentSkill.level}`)
          }
        }
      }
    },
    
    // 获取资源中文名称
    getResourceName(resource) {
      const names = {
        wood: '木材',
        stone: '石头',
        water: '淡水',
        food: '食物',
        energy: '精力',
        hp: '生命',
        hunger: '饥饿',
        shells: '贝壳',
        herbs: '草药',
        crystals: '水晶',
        hygiene: '清洁度',
        crafting: '制作经验',
        organization: '整理度',
        vines: '藤蔓',
        metal: '金属',
        mud: '泥土',
        mushrooms: '蘑菇',
        sand: '沙子',
        cactus: '仙人掌',
        reeds: '芦苇',
        scouting: '侦察经验'
      }
      return names[resource] || resource
    },
    
    // 存档管理方法
    openSaveModal() {
      this.loadSaveSlots()
      this.showSaveModal = true
    },
    
    closeSaveModal() {
      this.showSaveModal = false
    },
    
    loadSaveSlots() {
      // 加载手动存档
      for (let i = 0; i < this.saveSlots.length; i++) {
        const saveData = uni.getStorageSync(`save_${i}`)
        if (saveData) {
          this.saveSlots[i] = {
            data: saveData,
            date: saveData.date || '未知时间'
          }
        } else {
          this.saveSlots[i] = { data: null, date: null }
        }
      }
      
      // 加载自动存档
      let autoSave = uni.getStorageSync('autoSave')
      if (!autoSave) {
        // 如果没有新的自动存档，尝试加载旧的游戏状态
        const oldState = uni.getStorageSync('textSurvivalState')
        if (oldState) {
          try {
            autoSave = JSON.parse(oldState)
            autoSave.date = autoSave.date || '旧存档'
          } catch (e) {
            console.log('解析旧存档失败:', e)
          }
        }
      }
      
      if (autoSave) {
        this.autoSaveData = {
          data: autoSave,
          date: autoSave.date || '未知时间'
        }
      } else {
        this.autoSaveData = null
      }
    },
    
    saveGame(slotIndex) {
      const saveData = {
        hp: this.hp,
        hunger: this.hunger,
        energy: this.energy,
        day: this.day,
        inventory: this.inventory,
        currentLocationId: this.currentLocationId,
        mapTiles: this.mapTiles,
        buildings: this.buildings,
        techs: this.techs,
        researchPoints: this.researchPoints,
        date: new Date().toLocaleString('zh-CN')
      }
      
      uni.setStorageSync(`save_${slotIndex}`, saveData)
      this.saveSlots[slotIndex] = {
        data: saveData,
        date: saveData.date
      }
      
      uni.showToast({
        title: `已保存到存档 ${slotIndex + 1}`,
        icon: 'success',
        duration: 2000
      })
    },
    
    loadSave(slotIndex) {
      const saveData = this.saveSlots[slotIndex].data
      if (!saveData) {
        uni.showToast({
          title: '存档为空',
          icon: 'none',
          duration: 2000
        })
        return
      }
      
      // 恢复游戏状态
      this.hp = saveData.hp
      this.hunger = saveData.hunger
      this.energy = saveData.energy
      this.day = saveData.day
      this.inventory = saveData.inventory
      this.currentLocationId = saveData.currentLocationId
      this.mapTiles = saveData.mapTiles
      this.buildings = saveData.buildings
      this.techs = saveData.techs
      this.researchPoints = saveData.researchPoints
      
      this.refreshOptions()
      this.closeSaveModal()
      
      uni.showToast({
        title: `已加载存档 ${slotIndex + 1}`,
        icon: 'success',
        duration: 2000
      })
    },
    
    deleteSave(slotIndex) {
      uni.removeStorageSync(`save_${slotIndex}`)
      this.saveSlots[slotIndex] = { data: null, date: null }
      
      uni.showToast({
        title: `已删除存档 ${slotIndex + 1}`,
        icon: 'success',
        duration: 2000
      })
    },
    
    // 自动存档相关方法
    saveAutoSave() {
      const saveData = {
        hp: this.hp,
        hunger: this.hunger,
        energy: this.energy,
        day: this.day,
        inventory: this.inventory,
        currentLocationId: this.currentLocationId,
        mapTiles: this.mapTiles,
        buildings: this.buildings,
        techs: this.techs,
        researchPoints: this.researchPoints,
        date: new Date().toLocaleString('zh-CN')
      }
      
      uni.setStorageSync('autoSave', saveData)
      this.autoSaveData = {
        data: saveData,
        date: saveData.date
      }
      
      uni.showToast({
        title: '已保存自动存档',
        icon: 'success',
        duration: 2000
      })
    },
    
    loadAutoSave() {
      if (!this.autoSaveData) {
        uni.showToast({
          title: '无自动存档',
          icon: 'none',
          duration: 2000
        })
        return
      }
      
      const saveData = this.autoSaveData.data
      
      // 恢复游戏状态
      this.hp = saveData.hp
      this.hunger = saveData.hunger
      this.energy = saveData.energy
      this.day = saveData.day
      this.inventory = saveData.inventory || this.inventory
      this.currentLocationId = saveData.currentLocationId || this.currentLocationId
      this.mapTiles = saveData.mapTiles || this.mapTiles
      this.buildings = saveData.buildings || this.buildings
      this.techs = saveData.techs || this.techs
      this.researchPoints = saveData.researchPoints || this.researchPoints
      
      // 恢复其他状态
      if (saveData.logs) this.logs = saveData.logs
      if (saveData.sceneText) this.sceneText = saveData.sceneText
      if (saveData.currentEventId) this.currentEventId = saveData.currentEventId
      if (saveData.buffs) this.buffs = saveData.buffs
      
      this.refreshOptions()
      this.closeSaveModal()
      
      uni.showToast({
        title: '已加载自动存档',
        icon: 'success',
        duration: 2000
      })
    },
    
    deleteAutoSave() {
      uni.removeStorageSync('autoSave')
      uni.removeStorageSync('textSurvivalState')
      this.autoSaveData = null
      
      uni.showToast({
        title: '已删除自动存档',
        icon: 'success',
        duration: 2000
      })
    },
    
    // 睡觉休息（包含结束这一天）
    async sleep() {
      if (this.energy >= 100) {
        uni.showToast({
          title: '精力已满，无需休息',
          icon: 'none',
          duration: 2000
        })
        return
      }
      
      // 恢复状态
      this.energy = Math.min(100, this.energy + 30)
      this.hp = Math.min(100, this.hp + 5)
      
      // 结束这一天
      this.day++
      this.hunger = Math.max(0, this.hunger - 10)
      this.energy = Math.max(0, this.energy - 5)
      
      this.pushLog('你休息了一晚，恢复了体力和生命值')
      this.pushLog(`第${this.day}天开始了`)
      
      // ========== 【新增】每日推进和结局检查 ==========
      await this.advanceGameDay()
      // ==============================================
      
      // 触发新的一天事件
      this.triggerNewDayEvent()
      
      this.saveState()
    },
    
    /**
     * 【新增】每日推进（调用game-manager）
     */
    async advanceGameDay() {
      // 同步状态到game-manager
      this.syncStateToManager()
      
      // 调用game-manager的每日推进
      await gameManager.advanceDay()
      
      // 同步新属性回来
      const state = gameManager.getState()
      this.thirst = state.thirst
      this.sanity = state.sanity
      this.temperature = state.temperature
      
      // 检查结局
      const endings = gameManager.checkEndings()
      if (endings.length > 0) {
        this.triggerEnding(endings[0])
      }
      
      // 加载新的每日一言
      try {
        this.todayQuote = await dailyQuote.getTodayQuote(this.day)
        if (this.todayQuote) {
          this.showDailyQuote = true
        }
      } catch (error) {
        console.error('[DailyQuote] 加载失败:', error)
      }
    },
    
    /**
     * 【新增】触发结局
     */
    triggerEnding(endingId) {
      const ending = gameManager.getEndingInfo(endingId)
      if (!ending) return
      
      // 使用uni.showModal显示结局
      uni.showModal({
        title: `🎉 ${ending.title}`,
        content: ending.description,
        showCancel: false,
        confirmText: '查看详情',
        success: (res) => {
          if (res.confirm) {
            // 可以跳转到结局详情页面，或显示更多信息
            this.pushLog(`════════════════════════════════`)
            this.pushLog(`🎉 达成结局：${ending.title}`)
            this.pushLog(`${ending.description}`)
            this.pushLog(`════════════════════════════════`)
          }
        }
      })
      
      // 保存结局成就
      try {
        const achievedEndings = JSON.parse(uni.getStorageSync('achievedEndings') || '[]')
        if (!achievedEndings.includes(endingId)) {
          achievedEndings.push(endingId)
          uni.setStorageSync('achievedEndings', JSON.stringify(achievedEndings))
          this.pushLog(`🏆 新成就：解锁了"${ending.title}"结局！`)
        }
      } catch (error) {
        console.error('[Ending] 保存失败:', error)
      }
    },
    
    // 触发新的一天事件
    triggerNewDayEvent() {
      // 随机事件
      if (Math.random() < 0.3) {
        const events = [
          () => this.applyEffects({ hp: -5 }, '夜晚的寒冷让你感到不适。'),
          () => this.applyEffects({ hunger: -8 }, '一夜未进食，你感到更加饥饿。'),
          () => this.applyEffects({ energy: -10 }, '睡眠质量不佳，你感到疲惫。')
        ]
        const evt = events[Math.floor(Math.random() * events.length)]
        evt()
      }
    },
    
    // 初始化瓦片地图
    initializeTileMap() {
      // 创建空的瓦片地图数据
      const mapWidth = 10
      const mapHeight = 10
      const totalTiles = mapWidth * mapHeight
      
      // 初始化已探索和已发现的瓦片数组
      this.tileMapExplored = Array(totalTiles).fill(false)
      this.tileMapRevealed = Array(totalTiles).fill(false)
      
      // 设置初始位置周围的瓦片为已发现
      const centerX = this.currentMapPosition.x
      const centerY = this.currentMapPosition.y
      
      for (let y = Math.max(0, centerY - 2); y <= Math.min(mapHeight - 1, centerY + 2); y++) {
        for (let x = Math.max(0, centerX - 2); x <= Math.min(mapWidth - 1, centerX + 2); x++) {
          const index = y * mapWidth + x
          this.tileMapRevealed[index] = true
          
          // 当前位置和相邻位置设为已探索
          if (Math.abs(x - centerX) <= 1 && Math.abs(y - centerY) <= 1) {
            this.tileMapExplored[index] = true
          }
        }
      }
    },
    
    // 更新瓦片地图位置
    updateMapPosition(position) {
      this.currentMapPosition = position
      this.saveState()
    },
    
    // 更新已探索的瓦片
    updateExploredTiles(tileIndex) {
      this.tileMapExplored[tileIndex] = true
      this.saveState()
    },
    
    // 更新已发现的瓦片
    updateRevealedTiles(tileIndices) {
      for (const index of tileIndices) {
        this.tileMapRevealed[index] = true
      }
      this.saveState()
    },
  }
}
</script>

<style scoped>
/* 增强的样式实现 */
.text-survival-container { 
  min-height: 100vh; 
  background: linear-gradient(135deg, #1e293b 0%, #334155 100%); 
  padding: 20rpx 20rpx 120rpx 20rpx; 
  position: relative;
  overflow: hidden;
}

.header { 
  display: flex; 
  align-items: center; 
  justify-content: space-between; 
  margin-bottom: 16rpx; 
}

.title { 
  font-size: 32rpx; 
  font-weight: bold; 
  color: #f8fafc; 
  text-shadow: 0 2rpx 4rpx rgba(0,0,0,0.3);
}

.badges { 
  display: flex; 
  gap: 8rpx; 
}

.badge { 
  font-size: 20rpx; 
  padding: 4rpx 10rpx; 
  border-radius: 10rpx; 
  color: #fff; 
  animation: pulse 2s infinite;
}

.badge.new { background: #ef4444; }
.badge.survival { background: #10b981; }

.status-bar { 
  display: grid; 
  grid-template-columns: 1fr 1fr; 
  gap: 12rpx; 
  background: rgba(255,255,255,0.06); 
  border: 1rpx solid rgba(255,255,255,0.1); 
  border-radius: 12rpx; 
  padding: 12rpx; 
  margin-bottom: 16rpx; 
  transition: all 0.3s ease;
}

.status-item { 
  display: flex; 
  align-items: center; 
  gap: 8rpx; 
  color: #e5e7eb; 
  transition: all 0.3s ease;
}

.status-item.status-critical {
  background: rgba(239, 68, 68, 0.1);
  border: 1rpx solid rgba(239, 68, 68, 0.3);
  border-radius: 8rpx;
  padding: 4rpx;
}

.label { 
  font-size: 20rpx; 
  width: 60rpx; 
  font-weight: bold;
}

.bar { 
  flex: 1; 
  height: 14rpx; 
  background: rgba(255,255,255,0.1); 
  border-radius: 8rpx; 
  overflow: hidden; 
  position: relative;
}

.fill { 
  height: 100%; 
  border-radius: 8rpx; 
  transition: width 0.5s ease;
  position: relative;
}

.fill.pulse {
  animation: pulse 1s infinite;
}

.fill.hp { background: linear-gradient(90deg, #ef4444, #f87171); }
.fill.hunger { background: linear-gradient(90deg, #f59e0b, #fbbf24); }
.fill.energy { background: linear-gradient(90deg, #3b82f6, #60a5fa); }
.fill.thirst { background: linear-gradient(90deg, #06b6d4, #22d3ee); }
.fill.sanity { background: linear-gradient(90deg, #8b5cf6, #a78bfa); }

.value { 
  width: 80rpx; 
  text-align: right; 
  font-size: 20rpx; 
  color: #cbd5e1; 
  font-weight: bold;
}

.value.critical {
  color: #ef4444;
  animation: pulse 1s infinite;
}

.day { 
  font-size: 22rpx; 
  color: #fcd34d; 
  font-weight: bold; 
  text-shadow: 0 1rpx 2rpx rgba(0,0,0,0.3);
}

/* ==================== 每日一言横幅 ==================== */
.daily-quote-banner {
  position: relative;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 20rpx 50rpx 20rpx 20rpx;
  margin-bottom: 16rpx;
  border-radius: 12rpx;
  box-shadow: 0 4rpx 12rpx rgba(102, 126, 234, 0.3);
  cursor: pointer;
  transition: all 0.3s ease;
}

.daily-quote-banner:hover {
  transform: translateY(-2rpx);
  box-shadow: 0 6rpx 16rpx rgba(102, 126, 234, 0.4);
}

.quote-text {
  display: block;
  font-size: 26rpx;
  line-height: 1.5;
  margin-bottom: 8rpx;
  font-weight: 500;
}

.quote-meta {
  display: block;
  font-size: 20rpx;
  opacity: 0.8;
}

.quote-close {
  position: absolute;
  right: 15rpx;
  top: 50%;
  transform: translateY(-50%);
  font-size: 40rpx;
  font-weight: bold;
  opacity: 0.7;
  transition: opacity 0.3s ease;
}

.quote-close:hover {
  opacity: 1;
}

/* ==================== 简化状态栏 ==================== */
.status-mini-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255,255,255,0.06);
  border: 1rpx solid rgba(255,255,255,0.1);
  border-radius: 12rpx;
  padding: 12rpx 16rpx;
  margin-bottom: 16rpx;
  height: 60rpx;
  cursor: pointer;
  transition: all 0.3s ease;
}

.status-mini-bar:hover {
  background: rgba(255,255,255,0.08);
  border-color: rgba(255,255,255,0.2);
  transform: translateY(-2rpx);
}

.status-mini-bar .status-item {
  font-size: 22rpx;
  font-weight: bold;
  color: #cbd5e1;
  white-space: nowrap;
}

.status-mini-bar .status-item.critical {
  color: #ef4444;
  animation: pulse 1s infinite;
}

.status-mini-bar .more-hint {
  font-size: 20rpx;
  color: #94a3b8;
  opacity: 0.8;
}

/* ==================== 状态详情Sheet ==================== */
.status-detail-sheet {
  padding: 20rpx;
}

.status-section {
  margin-bottom: 32rpx;
}

.status-section:last-child {
  margin-bottom: 0;
}

.section-title {
  display: block;
  font-size: 28rpx;
  font-weight: bold;
  color: #f8fafc;
  margin-bottom: 20rpx;
  padding-bottom: 12rpx;
  border-bottom: 2rpx solid rgba(255,255,255,0.1);
}

.detail-item {
  margin-bottom: 20rpx;
}

.item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8rpx;
}

.item-label {
  font-size: 24rpx;
  color: #e2e8f0;
  font-weight: 500;
}

.item-value {
  font-size: 22rpx;
  font-weight: bold;
}

.progress-bar {
  height: 20rpx;
  background: rgba(255,255,255,0.1);
  border-radius: 10rpx;
  overflow: hidden;
  position: relative;
}

.progress-fill {
  height: 100%;
  border-radius: 10rpx;
  transition: width 0.5s ease;
}

.progress-fill.hp {
  background: linear-gradient(90deg, #ef4444, #f87171);
}

.progress-fill.hunger {
  background: linear-gradient(90deg, #f59e0b, #fbbf24);
}

.progress-fill.energy {
  background: linear-gradient(90deg, #3b82f6, #60a5fa);
}

.progress-fill.thirst {
  background: linear-gradient(90deg, #06b6d4, #22d3ee);
}

.progress-fill.sanity {
  background: linear-gradient(90deg, #8b5cf6, #a78bfa);
}

.buff-list {
  display: flex;
  flex-direction: column;
  gap: 12rpx;
}

.buff-item {
  display: flex;
  align-items: flex-start;
  gap: 12rpx;
  background: rgba(255,255,255,0.05);
  padding: 16rpx;
  border-radius: 12rpx;
  border: 1rpx solid rgba(255,255,255,0.1);
}

.buff-icon {
  font-size: 32rpx;
  line-height: 1;
}

.buff-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4rpx;
}

.buff-name {
  font-size: 24rpx;
  font-weight: bold;
  color: #f8fafc;
}

.buff-desc {
  font-size: 20rpx;
  color: #cbd5e1;
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16rpx;
}

.stat-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: rgba(255,255,255,0.05);
  padding: 20rpx;
  border-radius: 16rpx;
  border: 1rpx solid rgba(255,255,255,0.1);
  gap: 8rpx;
}

.stat-icon {
  font-size: 40rpx;
}

.stat-label {
  font-size: 20rpx;
  color: #94a3b8;
}

.stat-value {
  font-size: 24rpx;
  font-weight: bold;
  color: #f8fafc;
}

/* ==================== 技能树样式 ==================== */
.skills-list {
  display: flex;
  flex-direction: column;
  gap: 16rpx;
}

.skill-item {
  background: rgba(255,255,255,0.05);
  padding: 16rpx;
  border-radius: 12rpx;
  border: 1rpx solid rgba(255,255,255,0.1);
}

.skill-header {
  display: flex;
  align-items: center;
  gap: 12rpx;
  margin-bottom: 8rpx;
}

.skill-icon {
  font-size: 36rpx;
  line-height: 1;
}

.skill-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6rpx;
}

.skill-name {
  font-size: 24rpx;
  font-weight: bold;
  color: #f8fafc;
}

.skill-exp-bar {
  height: 12rpx;
  background: rgba(255,255,255,0.1);
  border-radius: 6rpx;
  overflow: hidden;
}

.skill-exp-fill {
  height: 100%;
  background: linear-gradient(90deg, #8b5cf6, #a78bfa);
  border-radius: 6rpx;
  transition: width 0.5s ease;
}

.skill-exp-text {
  font-size: 18rpx;
  color: #94a3b8;
}

.skill-bonus {
  font-size: 20rpx;
  color: #10b981;
  text-align: right;
}

/* ==================== 结局收集样式 ==================== */
.endings-list {
  display: flex;
  flex-direction: column;
  gap: 12rpx;
}

.ending-item {
  display: flex;
  align-items: center;
  gap: 12rpx;
  background: rgba(255,255,255,0.05);
  padding: 16rpx;
  border-radius: 12rpx;
  border: 1rpx solid rgba(255,255,255,0.1);
}

.ending-item.locked {
  opacity: 0.5;
  border-style: dashed;
}

.ending-icon {
  font-size: 32rpx;
  line-height: 1;
}

.ending-name {
  flex: 1;
  font-size: 24rpx;
  color: #f8fafc;
  font-weight: 500;
}

.scene { 
  background: rgba(255,255,255,0.06); 
  border: 1rpx solid rgba(255,255,255,0.1); 
  border-radius: 12rpx; 
  padding: 16rpx; 
  margin-bottom: 12rpx; 
  position: relative;
  overflow: hidden;
  transition: all 0.3s ease;
}

.scene.scene-animate {
  transform: scale(1.02);
  box-shadow: 0 4rpx 20rpx rgba(0,0,0,0.2);
}

.scene-content {
  position: relative;
  z-index: 2;
}

.scene-text { 
  font-size: 24rpx; 
  color: #e2e8f0; 
  line-height: 1.6; 
  transition: all 0.3s ease;
}

.scene-text.typing {
  border-right: 2rpx solid #e2e8f0;
  animation: blink 1s infinite;
}

.typing-indicator {
  color: #94a3b8;
  font-size: 20rpx;
  animation: pulse 1s infinite;
}

.scene-effects {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1;
}

.effect-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  border-radius: 12rpx;
  animation: fadeInOut 1s ease;
}

.effect-overlay.heal {
  background: linear-gradient(45deg, rgba(16, 185, 129, 0.1), rgba(34, 197, 94, 0.1));
}

.effect-overlay.damage {
  background: linear-gradient(45deg, rgba(239, 68, 68, 0.1), rgba(220, 38, 38, 0.1));
}

.effect-overlay.eat {
  background: linear-gradient(45deg, rgba(245, 158, 11, 0.1), rgba(251, 191, 36, 0.1));
}

.effect-overlay.rest {
  background: linear-gradient(45deg, rgba(59, 130, 246, 0.1), rgba(96, 165, 250, 0.1));
}

.effect-overlay.hunger {
  background: linear-gradient(45deg, rgba(239, 68, 68, 0.1), rgba(185, 28, 28, 0.1));
}

.effect-overlay.tired {
  background: linear-gradient(45deg, rgba(107, 114, 128, 0.1), rgba(75, 85, 99, 0.1));
}

.effect-overlay.injured {
  background: linear-gradient(45deg, rgba(220, 38, 38, 0.1), rgba(153, 27, 27, 0.1));
}

.effect-overlay.move {
  background: linear-gradient(45deg, rgba(102, 126, 234, 0.1), rgba(59, 130, 246, 0.1));
  animation: moveEffect 0.6s ease-in-out;
}

@keyframes moveEffect {
  0% { 
    opacity: 0; 
    transform: scale(0.8);
  }
  50% { 
    opacity: 1; 
    transform: scale(1.1);
  }
  100% { 
    opacity: 0; 
    transform: scale(1);
  }
}

/* 当前位置动画 */
@keyframes currentLocationPulse {
  0%, 100% { 
    box-shadow: 0 8rpx 32rpx rgba(102, 126, 234, 0.5);
    transform: scale(1);
  }
  50% { 
    box-shadow: 0 12rpx 40rpx rgba(102, 126, 234, 0.8);
    transform: scale(1.02);
  }
}

@keyframes currentIconGlow {
  0%, 100% { 
    filter: drop-shadow(0 0 8rpx rgba(102, 126, 234, 0.5));
    transform: scale(1);
  }
  50% { 
    filter: drop-shadow(0 0 16rpx rgba(102, 126, 234, 0.8));
    transform: scale(1.1);
  }
}

.options { 
  display: grid; 
  grid-template-columns: 1fr 1fr; 
  gap: 12rpx; 
  margin-bottom: 16rpx; 
}

.option-btn { 
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); 
  color: white; 
  border: none; 
  border-radius: 12rpx; 
  padding: 14rpx; 
  font-size: 24rpx; 
  position: relative;
  transition: all 0.3s ease;
  overflow: hidden;
}

.option-btn:hover {
  transform: translateY(-2rpx);
  box-shadow: 0 4rpx 12rpx rgba(0,0,0,0.2);
}

.option-btn.option-disabled {
  opacity: 0.5;
  pointer-events: none;
}

.option-btn.special {
  background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
}

.option-text {
  display: block;
  margin-bottom: 4rpx;
}

.risk-indicator {
  position: absolute;
  top: 4rpx;
  right: 4rpx;
  font-size: 16rpx;
  padding: 2rpx 6rpx;
  border-radius: 6rpx;
  font-weight: bold;
}

.risk-indicator.risk-低 {
  background: rgba(16, 185, 129, 0.8);
  color: white;
}

.risk-indicator.risk-中 {
  background: rgba(245, 158, 11, 0.8);
  color: white;
}

.risk-indicator.risk-高 {
  background: rgba(239, 68, 68, 0.8);
  color: white;
}

.special-indicator {
  position: absolute;
  top: 4rpx;
  right: 4rpx;
  font-size: 16rpx;
  padding: 2rpx 6rpx;
  border-radius: 6rpx;
  background: rgba(255, 255, 255, 0.2);
  color: white;
  font-weight: bold;
}

.log-section { 
  background: rgba(255,255,255,0.06); 
  border: 1rpx solid rgba(255,255,255,0.1); 
  border-radius: 12rpx; 
  padding: 12rpx; 
}

.log-title { 
  display: block; 
  color: #cbd5e1; 
  font-size: 22rpx; 
  margin-bottom: 8rpx; 
  font-weight: bold;
}

.log-list { 
  max-height: 200rpx; 
  margin-bottom: 20rpx;
}

.log-line { 
  font-size: 20rpx; 
  color: #94a3b8; 
  padding: 6rpx 0; 
  border-bottom: 1rpx dashed rgba(255,255,255,0.08); 
  transition: all 0.3s ease;
}

.log-line:hover {
  background: rgba(255,255,255,0.05);
  padding-left: 8rpx;
}

.actions { 
  display: flex; 
  gap: 12rpx; 
  margin-top: 12rpx; 
}

.action-btn { 
  flex: 1; 
  background: #10b981; 
  color: #fff; 
  border: none; 
  border-radius: 10rpx; 
  padding: 12rpx; 
  font-size: 24rpx; 
  transition: all 0.3s ease;
}

.action-btn:hover {
  transform: translateY(-2rpx);
  box-shadow: 0 4rpx 12rpx rgba(16, 185, 129, 0.3);
}

.action-btn.secondary { 
  background: #64748b; 
}

/* AI 控件样式 */
.ai-bar { 
  display: flex; 
  align-items: center; 
  justify-content: space-between;
  background: rgba(255,255,255,0.06); 
  border: 1rpx solid rgba(255,255,255,0.1); 
  border-radius: 12rpx; 
  padding: 16rpx; 
  margin-bottom: 12rpx; 
}

.ai-switch { 
  display: flex; 
  align-items: center; 
  gap: 12rpx; 
}

.ai-label { 
  color: #e5e7eb; 
  font-size: 24rpx; 
  font-weight: 500;
}

.ai-test-btn {
  background: #3b82f6;
  color: #fff;
  border: none;
  border-radius: 8rpx;
  padding: 8rpx 16rpx;
  font-size: 20rpx;
  margin-left: 12rpx;
  transition: all 0.3s ease;
}

.ai-test-btn:disabled {
  background: #64748b;
  opacity: 0.5;
}

.ai-test-btn:not(:disabled):hover {
  background: #2563eb;
  transform: translateY(-1rpx);
}

/* 动画效果 */
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

@keyframes blink {
  0%, 50% { border-color: #e2e8f0; }
  51%, 100% { border-color: transparent; }
}

@keyframes fadeInOut {
  0% { opacity: 0; }
  50% { opacity: 1; }
  100% { opacity: 0; }
}

/* 头部按钮样式 */
.header-actions {
  display: flex;
  align-items: center;
  gap: 12rpx;
}

.restart-btn, .save-btn {
  padding: 8rpx 16rpx;
  border-radius: 8rpx;
  font-size: 24rpx;
  border: none;
  cursor: pointer;
  transition: all 0.3s ease;
  min-width: 80rpx;
  height: 48rpx;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.restart-btn {
  background: #ef4444;
  color: #fff;
}

.restart-btn:hover {
  background: #dc2626;
  transform: scale(1.05);
}

.save-btn {
  background: #3b82f6;
  color: #fff;
}

.save-btn:hover {
  background: #2563eb;
  transform: scale(1.05);
}

/* 存档弹窗样式 */
.save-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1500;
}

.save-list {
  display: flex;
  flex-direction: column;
  gap: 16rpx;
  padding: 20rpx;
}

.save-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16rpx 20rpx;
  background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
  border-radius: 12rpx;
  border: 2rpx solid rgba(255, 255, 255, 0.1);
  cursor: pointer;
  transition: all 0.3s ease;
}

.save-item:hover {
  transform: translateY(-2rpx);
  border-color: #4b5563;
}

.save-item.auto-save {
  background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
  border: 2rpx solid #3b82f6;
}

.save-item.auto-save:hover {
  border-color: #2563eb;
}

.save-info {
  display: flex;
  flex-direction: column;
  gap: 4rpx;
}

.save-name {
  font-size: 28rpx;
  font-weight: bold;
  color: #f8fafc;
}

.save-date {
  font-size: 24rpx;
  color: #94a3b8;
}

.save-status {
  font-size: 24rpx;
  color: #64748b;
}

.save-actions {
  display: flex;
  gap: 8rpx;
}

.save-action-btn {
  padding: 8rpx 16rpx;
  border-radius: 8rpx;
  font-size: 24rpx;
  border: none;
  cursor: pointer;
  transition: all 0.3s ease;
  background: #3b82f6;
  color: #fff;
}

.save-action-btn:hover {
  background: #2563eb;
  transform: scale(1.05);
}

.save-action-btn.delete {
  background: #ef4444;
}

.save-action-btn.delete:hover {
  background: #dc2626;
}

/* 底部Tab导航样式 */
.bottom-tabs {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(30, 41, 59, 0.95);
  border-top: 1rpx solid rgba(255, 255, 255, 0.1);
  display: flex;
  padding: 8rpx 0;
  backdrop-filter: blur(10rpx);
  z-index: 1000;
  height: 100rpx;
}

.tab-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8rpx 4rpx;
  transition: all 0.3s ease;
  cursor: pointer;
}

.tab-item.active {
  background: rgba(102, 126, 234, 0.2);
  border-radius: 8rpx;
}

.tab-icon {
  font-size: 24rpx;
  margin-bottom: 4rpx;
  transition: all 0.3s ease;
}

.tab-item.active .tab-icon {
  transform: scale(1.1);
}

.tab-text {
  font-size: 18rpx;
  color: #94a3b8;
  transition: all 0.3s ease;
}

.tab-item.active .tab-text {
  color: #667eea;
  font-weight: bold;
}

/* 当前位置信息样式 */
.current-location-info {
  margin-bottom: 20rpx;
}

.location-card {
  display: flex;
  align-items: center;
  gap: 16rpx;
  padding: 16rpx 20rpx;
  background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
  border-radius: 12rpx;
  border: 2rpx solid rgba(255, 255, 255, 0.1);
}

.location-icon {
  font-size: 32rpx;
  flex-shrink: 0;
}

.location-details {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4rpx;
}

.location-name {
  font-size: 28rpx;
  font-weight: bold;
  color: #f8fafc;
}

.location-desc {
  font-size: 24rpx;
  color: #94a3b8;
  line-height: 1.4;
}

/* 弹窗样式 */
.map-modal, .build-modal, .tech-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* 确保Toast提示能正确显示 */
.uni-toast {
  z-index: 3000 !important;
}

/* 建筑网格样式 */
.buildings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300rpx, 1fr));
  gap: 20rpx;
  padding: 20rpx;
  max-height: 70vh;
  overflow-y: auto;
}

.building-item {
  background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
  border: 2rpx solid #475569;
  border-radius: 16rpx;
  padding: 20rpx;
  text-align: left;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.2);
  position: relative;
}

.building-item:hover {
  transform: translateY(-4rpx);
  box-shadow: 0 8rpx 20rpx rgba(0, 0, 0, 0.3);
  border-color: #64748b;
}

.building-item.built {
  background: linear-gradient(135deg, #065f46 0%, #047857 100%);
  border-color: #10b981;
  box-shadow: 0 4rpx 12rpx rgba(16, 185, 129, 0.3);
}

.building-item.can-build {
  border-color: #3b82f6;
  background: linear-gradient(135deg, #1e3a8a 0%, #3b82f6 100%);
  box-shadow: 0 4rpx 12rpx rgba(59, 130, 246, 0.3);
}

.building-item.cannot-build {
  opacity: 0.6;
  border-color: #ef4444;
  background: linear-gradient(135deg, #7f1d1d 0%, #ef4444 100%);
}

.building-icon {
  font-size: 48rpx;
  display: block;
  margin-bottom: 12rpx;
  text-align: center;
}

.building-name {
  font-size: 28rpx;
  font-weight: bold;
  color: #f8fafc;
  display: block;
  margin-bottom: 8rpx;
  text-align: center;
}

.building-level {
  font-size: 24rpx;
  color: #10b981;
  font-weight: bold;
  display: block;
  margin-bottom: 8rpx;
  text-align: center;
}

.building-status {
  font-size: 24rpx;
  color: #94a3b8;
  display: block;
  text-align: center;
  margin-bottom: 8rpx;
}

.building-description {
  font-size: 22rpx;
  color: #cbd5e1;
  display: block;
  margin-bottom: 8rpx;
  line-height: 1.4;
}

.building-production {
  font-size: 20rpx;
  color: #10b981;
  display: block;
  margin-bottom: 12rpx;
  font-weight: 500;
}

.building-cost, .building-upgrade-cost {
  background: rgba(0, 0, 0, 0.3);
  border-radius: 8rpx;
  padding: 8rpx 12rpx;
  margin-bottom: 8rpx;
}

.cost-label {
  font-size: 20rpx;
  color: #fbbf24;
  font-weight: bold;
  display: block;
  margin-bottom: 4rpx;
}

.cost-items {
  font-size: 18rpx;
  color: #e5e7eb;
  display: block;
}

.building-prerequisites {
  background: rgba(239, 68, 68, 0.2);
  border: 1rpx solid rgba(239, 68, 68, 0.3);
  border-radius: 8rpx;
  padding: 8rpx 12rpx;
}

.prereq-label {
  font-size: 20rpx;
  color: #ef4444;
  font-weight: bold;
  display: block;
  margin-bottom: 4rpx;
}

.prereq-items {
  font-size: 18rpx;
  color: #fca5a5;
  display: block;
}

/* 科技列表样式 */
.tech-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(350rpx, 1fr));
  gap: 20rpx;
  padding: 20rpx;
  max-height: 70vh;
  overflow-y: auto;
}

.tech-item {
  background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
  border: 2rpx solid #475569;
  border-radius: 16rpx;
  padding: 20rpx;
  text-align: left;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.2);
  position: relative;
}

.tech-item:hover {
  transform: translateY(-4rpx);
  box-shadow: 0 8rpx 20rpx rgba(0, 0, 0, 0.3);
  border-color: #64748b;
}

.tech-item.completed {
  background: linear-gradient(135deg, #065f46 0%, #047857 100%);
  border-color: #10b981;
  box-shadow: 0 4rpx 12rpx rgba(16, 185, 129, 0.3);
}

.tech-item.researching {
  background: linear-gradient(135deg, #7c2d12 0%, #ea580c 100%);
  border-color: #f97316;
  box-shadow: 0 4rpx 12rpx rgba(249, 115, 22, 0.3);
  animation: pulse 2s ease-in-out infinite;
}

.tech-item.can-research {
  border-color: #3b82f6;
  background: linear-gradient(135deg, #1e3a8a 0%, #3b82f6 100%);
  box-shadow: 0 4rpx 12rpx rgba(59, 130, 246, 0.3);
}

.tech-item.cannot-research {
  opacity: 0.6;
  border-color: #ef4444;
  background: linear-gradient(135deg, #7f1d1d 0%, #ef4444 100%);
}

.tech-icon {
  font-size: 48rpx;
  display: block;
  margin-bottom: 12rpx;
  text-align: center;
}

.tech-name {
  font-size: 28rpx;
  font-weight: bold;
  color: #f8fafc;
  display: block;
  margin-bottom: 8rpx;
  text-align: center;
}

.tech-category {
  font-size: 20rpx;
  color: #93c5fd;
  background: rgba(147, 197, 253, 0.1);
  padding: 4rpx 8rpx;
  border-radius: 8rpx;
  border: 1rpx solid rgba(147, 197, 253, 0.3);
  display: inline-block;
  margin-bottom: 8rpx;
  text-align: center;
  width: 100%;
}

.tech-description {
  font-size: 22rpx;
  color: #cbd5e1;
  display: block;
  margin-bottom: 8rpx;
  line-height: 1.4;
}

.tech-status {
  font-size: 24rpx;
  color: #94a3b8;
  display: block;
  text-align: center;
  margin-bottom: 8rpx;
}

.tech-cost {
  font-size: 20rpx;
  color: #fbbf24;
  display: block;
  text-align: center;
  margin-bottom: 8rpx;
  font-weight: bold;
}

.tech-effects {
  background: rgba(0, 0, 0, 0.3);
  border-radius: 8rpx;
  padding: 8rpx 12rpx;
  margin-bottom: 8rpx;
}

.effects-label {
  font-size: 20rpx;
  color: #10b981;
  font-weight: bold;
  display: block;
  margin-bottom: 4rpx;
}

.effects-items {
  font-size: 18rpx;
  color: #e5e7eb;
  display: block;
}

.tech-prerequisites {
  background: rgba(239, 68, 68, 0.2);
  border: 1rpx solid rgba(239, 68, 68, 0.3);
  border-radius: 8rpx;
  padding: 8rpx 12rpx;
}

.prereq-label {
  font-size: 20rpx;
  color: #ef4444;
  font-weight: bold;
  display: block;
  margin-bottom: 4rpx;
}

.prereq-items {
  font-size: 18rpx;
  color: #fca5a5;
  display: block;
}

.modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(5rpx);
}

.map-modal-content, .modal-content {
  position: relative;
  background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
  border-radius: 20rpx;
  margin: 40rpx;
  width: calc(100% - 80rpx);
  height: calc(100% - 80rpx);
  max-width: 600rpx;
  max-height: 800rpx;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  border: 1rpx solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 8rpx 32rpx rgba(0, 0, 0, 0.3);
}

.map-modal-header, .modal-header {
  padding: 30rpx;
  border-bottom: 1rpx solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.05);
  display: flex;
  flex-direction: column;
  gap: 12rpx;
}

.modal-title {
  font-size: 32rpx;
  font-weight: bold;
  color: #f8fafc;
  text-align: center;
}

.exploration-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.exploration-points, .current-location {
  font-size: 22rpx;
  color: #667eea;
  font-weight: bold;
}

.close-btn {
  position: absolute;
  top: 20rpx;
  right: 20rpx;
  font-size: 36rpx;
  color: #94a3b8;
  background: none;
  border: none;
  padding: 10rpx;
  line-height: 1;
  transition: all 0.3s ease;
}

.close-btn:hover {
  color: #f8fafc;
  transform: scale(1.1);
}

.map-container {
  flex: 1;
  padding: 20rpx;
  overflow-y: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 400rpx;
}

/* 九宫格地图样式 */
.map-grid-3x3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10rpx;
  padding: 15rpx;
  max-width: 500rpx;
  width: 100%;
  margin: 0 auto;
  justify-items: center;
  align-items: center;
}

.map-card {
  width: 140rpx;
  height: 140rpx;
  perspective: 1000rpx;
  cursor: pointer;
  transition: all 0.3s ease;
  border-radius: 16rpx;
  overflow: hidden;
  position: relative;
}

.map-card:hover {
  transform: scale(1.05);
  z-index: 10;
}

.map-card:active {
  transform: scale(1.1);
}

.map-card.current {
  transform: scale(1.05);
}

.map-card.flipping {
  transform: scale(1.1);
  animation: flipCard 0.6s ease-in-out;
}

.map-card.switching {
  transform: scale(1.1);
  animation: switchLocation 0.6s ease-in-out;
}

@keyframes flipCard {
  0% { transform: scale(1) rotateY(0deg); }
  50% { transform: scale(1.1) rotateY(90deg); }
  100% { transform: scale(1) rotateY(180deg); }
}

@keyframes switchLocation {
  0% { 
    transform: scale(1); 
    box-shadow: 0 0 0 rgba(102, 126, 234, 0);
  }
  25% { 
    transform: scale(1.15); 
    box-shadow: 0 8rpx 32rpx rgba(102, 126, 234, 0.4);
  }
  50% { 
    transform: scale(1.1); 
    box-shadow: 0 12rpx 40rpx rgba(102, 126, 234, 0.6);
  }
  75% { 
    transform: scale(1.05); 
    box-shadow: 0 8rpx 32rpx rgba(102, 126, 234, 0.4);
  }
  100% { 
    transform: scale(1.05); 
    box-shadow: 0 6rpx 20rpx rgba(102, 126, 234, 0.3);
  }
}

.card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  text-align: center;
  border-radius: 16rpx;
  overflow: hidden;
}

.card-front, .card-back {
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 16rpx;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 12rpx;
  text-align: center;
  box-sizing: border-box;
}

.card-front {
  background: linear-gradient(135deg, #374151 0%, #4b5563 100%);
  border: 2rpx solid rgba(255, 255, 255, 0.3);
  color: #f8fafc;
  box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.3);
  border-radius: 16rpx;
}

.card-back {
  background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
  border: 2rpx solid rgba(255, 255, 255, 0.1);
  color: #f8fafc;
  border-radius: 16rpx;
}

.question-mark {
  font-size: 36rpx;
  font-weight: bold;
  color: #f59e0b;
  margin-bottom: 6rpx;
  animation: pulse 2s infinite;
  text-shadow: 0 2rpx 4rpx rgba(0, 0, 0, 0.5);
  line-height: 1;
}

.explore-cost {
  font-size: 14rpx;
  color: #94a3b8;
  text-align: center;
  line-height: 1.2;
  margin: 0;
  padding: 0;
}

.tile-icon {
  font-size: 28rpx;
  display: block;
  margin-bottom: 6rpx;
  line-height: 1;
}

.tile-name {
  font-size: 16rpx;
  color: #f8fafc;
  font-weight: bold;
  display: block;
  margin-bottom: 3rpx;
  line-height: 1.2;
  text-align: center;
}

.tile-status {
  font-size: 12rpx;
  color: #94a3b8;
  line-height: 1.2;
  text-align: center;
  margin: 0;
  padding: 0;
}

/* 卡片状态样式 */
.map-card.current .card-back {
  border-color: #667eea;
  background: linear-gradient(135deg, rgba(102, 126, 234, 0.2) 0%, rgba(59, 130, 246, 0.2) 100%);
  box-shadow: 0 8rpx 32rpx rgba(102, 126, 234, 0.5);
  animation: currentLocationPulse 2s ease-in-out infinite;
}

.map-card.current .tile-icon {
  animation: currentIconGlow 2s ease-in-out infinite;
}

.map-card.current .tile-name {
  color: #667eea;
  font-weight: bold;
  text-shadow: 0 2rpx 4rpx rgba(102, 126, 234, 0.3);
}

.map-card.current .tile-status {
  color: #667eea;
  font-weight: bold;
  background: rgba(102, 126, 234, 0.2);
  padding: 2rpx 8rpx;
  border-radius: 8rpx;
  border: 1rpx solid rgba(102, 126, 234, 0.3);
}

.map-card.explored .card-back {
  border-color: #10b981;
  background: rgba(16, 185, 129, 0.1);
}

.map-card.discovered .card-back {
  border-color: #f59e0b;
  background: rgba(245, 158, 11, 0.1);
}

.map-card.locked .card-front {
  opacity: 0.5;
  background: rgba(75, 85, 99, 0.3);
}

/* 精力不足时的样式 */
.map-card.insufficient-energy .card-front {
  opacity: 0.4;
  background: linear-gradient(135deg, #374151 0%, #4b5563 100%);
  border-color: rgba(239, 68, 68, 0.5);
  position: relative;
}

.map-card.insufficient-energy .card-front::after {
  content: '精力不足';
  position: absolute;
  bottom: 4rpx;
  left: 50%;
  transform: translateX(-50%);
  font-size: 10rpx;
  color: #ef4444;
  background: rgba(0, 0, 0, 0.7);
  padding: 2rpx 6rpx;
  border-radius: 4rpx;
  white-space: nowrap;
}

.map-card.insufficient-energy .question-mark {
  color: #ef4444;
  opacity: 0.6;
}

.map-card.insufficient-energy .explore-cost {
  color: #ef4444;
  font-weight: bold;
}

.current-marker {
  position: absolute;
  top: -8rpx;
  right: -8rpx;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 12rpx;
  padding: 4rpx 8rpx;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2rpx;
  box-shadow: 0 4rpx 12rpx rgba(102, 126, 234, 0.4);
  border: 2rpx solid rgba(255, 255, 255, 0.2);
  animation: currentMarkerPulse 2s ease-in-out infinite;
  z-index: 10;
}

.marker-icon {
  font-size: 16rpx;
  animation: markerIconBounce 1.5s ease-in-out infinite;
}

.marker-text {
  font-size: 10rpx;
  color: #fff;
  font-weight: bold;
  text-shadow: 0 1rpx 2rpx rgba(0, 0, 0, 0.3);
  white-space: nowrap;
  line-height: 1;
}

@keyframes currentMarkerPulse {
  0%, 100% { 
    transform: scale(1);
    box-shadow: 0 4rpx 12rpx rgba(102, 126, 234, 0.4);
  }
  50% { 
    transform: scale(1.1);
    box-shadow: 0 6rpx 16rpx rgba(102, 126, 234, 0.6);
  }
}

@keyframes markerIconBounce {
  0%, 100% { 
    transform: translateY(0);
  }
  50% { 
    transform: translateY(-2rpx);
  }
}

/* 响应式设计 */
@media screen and (max-width: 750rpx) {
  .map-card {
    width: 120rpx;
    height: 120rpx;
  }
  
  .tile-icon {
    font-size: 24rpx;
  }
  
  .tile-name {
    font-size: 14rpx;
  }
  
  .tile-status {
    font-size: 10rpx;
  }
  
  .question-mark {
    font-size: 32rpx;
  }
  
  .explore-cost {
    font-size: 12rpx;
  }
}

@media screen and (max-width: 600rpx) {
  .map-card {
    width: 100rpx;
    height: 100rpx;
  }
  
  .tile-icon {
  font-size: 20rpx;
  }
  
  .tile-name {
    font-size: 12rpx;
  }
  
  .tile-status {
    font-size: 8rpx;
  }
  
  .question-mark {
    font-size: 28rpx;
  }
  
  .explore-cost {
    font-size: 10rpx;
  }
  
  .current-marker {
    top: -6rpx;
    right: -6rpx;
    padding: 3rpx 6rpx;
  }
  
  .marker-icon {
    font-size: 12rpx;
  }
  
  .marker-text {
    font-size: 8rpx;
  }
}

/* 当前位置操作样式 */
.location-actions {
  padding: 20rpx;
  border-top: 1rpx solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.05);
}

.section-title {
  font-size: 24rpx;
  color: #f8fafc;
  font-weight: bold;
  margin-bottom: 16rpx;
  display: block;
}

.actions-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12rpx;
}

.action-item {
  background: rgba(255, 255, 255, 0.06);
  border: 2rpx solid rgba(255, 255, 255, 0.1);
  border-radius: 12rpx;
  padding: 16rpx;
  text-align: center;
  transition: all 0.3s ease;
  cursor: pointer;
}

.action-item:hover {
  transform: scale(1.02);
  box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.2);
  border-color: #667eea;
}

.action-icon {
  font-size: 24rpx;
  display: block;
  margin-bottom: 8rpx;
}

.action-name {
  font-size: 18rpx;
  color: #f8fafc;
  font-weight: bold;
  display: block;
  margin-bottom: 4rpx;
}

.action-cost {
  font-size: 14rpx;
  color: #94a3b8;
}

/* 建筑网格样式 */
.buildings-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16rpx;
  padding: 20rpx;
  flex: 1;
  overflow-y: auto;
}

.building-item {
  background: rgba(255, 255, 255, 0.06);
  border: 2rpx solid rgba(255, 255, 255, 0.1);
  border-radius: 16rpx;
  padding: 20rpx;
  text-align: center;
  transition: all 0.3s ease;
  cursor: pointer;
}

.building-item:hover {
  transform: scale(1.02);
  box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.2);
}

.building-item.built {
  border-color: #10b981;
  background: rgba(16, 185, 129, 0.1);
}

.building-icon {
  font-size: 32rpx;
  display: block;
  margin-bottom: 8rpx;
}

.building-name {
  font-size: 20rpx;
  color: #f8fafc;
  font-weight: bold;
  display: block;
  margin-bottom: 4rpx;
}

.building-status {
  font-size: 16rpx;
  color: #94a3b8;
}

/* 科技列表样式 */
.tech-list {
  padding: 20rpx;
  flex: 1;
  overflow-y: auto;
}

.tech-item {
  background: rgba(255, 255, 255, 0.06);
  border: 2rpx solid rgba(255, 255, 255, 0.1);
  border-radius: 16rpx;
  padding: 20rpx;
  margin-bottom: 16rpx;
  display: flex;
  align-items: center;
  gap: 16rpx;
  transition: all 0.3s ease;
  cursor: pointer;
}

.tech-item:hover {
  transform: scale(1.02);
  box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.2);
}

.tech-item.completed {
  border-color: #10b981;
  background: rgba(16, 185, 129, 0.1);
}

.tech-item.researching {
  border-color: #f59e0b;
  background: rgba(245, 158, 11, 0.1);
}

.tech-icon {
  font-size: 32rpx;
}

.tech-name {
  font-size: 20rpx;
  color: #f8fafc;
  font-weight: bold;
  flex: 1;
}

.tech-status {
  font-size: 16rpx;
  color: #94a3b8;
}

/* UI模式切换按钮 */
.ui-mode-toggle {
  position: fixed;
  top: 20rpx;
  left: 20rpx;
  background: rgba(59, 130, 246, 0.8);
  color: white;
  border: none;
  border-radius: 10rpx;
  padding: 8rpx 16rpx;
  font-size: 24rpx;
  z-index: 1000;
  box-shadow: 0 4rpx 8rpx rgba(0, 0, 0, 0.3);
  transition: all 0.3s ease;
}

.ui-mode-toggle:hover {
  background: rgba(37, 99, 235, 0.9);
  transform: translateY(-2rpx);
  box-shadow: 0 6rpx 12rpx rgba(0, 0, 0, 0.4);
}
</style> 